Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Copper Contributor
Posts: 248
Registered: ‎04-20-2009

Prepopulated 'owner' lookup won't save data on insertdefects quickform

I am trying to default a couple of lookups on the insert defects quickform in a c# code snip in the Load Actions. If I choose the values by activating the lookup the values save fine.  As it is now the values appear to prepopulate correctly when the form displays but don't get saved to the db. One of the lookups is the oob  Owner field. This defaults to 'Everyone' even though I am prepopulating with a team called 'Defects'. The other is a custom lookup called Reported By. This appears to prepopulate with the logged on user but saves no data to the db. Again, if I use the lookups to choose values manaully they are saved correctly.

 

Here is the code I am using to prepopulate:

//prepopulate owner lookup
lueOwner.LookupResultValue = "F6UJ9A00002I"; //hardcode to be changed when code working
lueOwner.Text = "Defects";

//prepopluate reported by lookup
Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
string currentUserId = userService.UserId;
lueReported.LookupResultValue = currentUserId;
lueReported.Text = userService.UserName.ToString();

Employee
Posts: 320
Registered: ‎03-30-2009

Re: Prepopulated 'owner' lookup won't save data on insertdefects quickform

The Owner field on Defect is being populated by the OnCreate Business Rule.

 

You could override this by changing the business rule to point to a code snippet instead (or I wrote my own external Business Rule DLL).

 

Instead of working with the form controls, work with the underlying entity instead.


But I beleive that if on your lookup control you set the .LookupResultValue to an Owner Entity instead of just the ID, it would work (check you lookup's "Lookup Binding Mode" - it is probaby set to "Object" and not "String"?)

 

Below is my own OnCreate Business Rule.  You'll see that I set the default "Owner" to an Owner Entity & not just the ID.  Same with the ReportedBy property (from the current user).

 

/// <summary> /// Called when [create]. /// </summary> /// <param name="defect">The defect.</param> public static void OnCreate(IDefect defect) { User user = SLXDTS.GetCurrentUser(); defect.Status = DefectStatus.New; defect.DefectType = "Defect"; defect.Priority = DefectPriority.Medium; defect.Severity = DefectSeverity.Medium; defect.Owner = Owner.GetByOwnerId(Owner.SystemEveryone); defect.RecordedDate = DateTime.UtcNow; if (user != null) { defect.RecordedBy = user.DefaultOwner; } defect.SubmitSearch = user.UserInfo.DefaultAddKnowledge; defect.DefectPublish.Publish = true; }

 

 

 

And here's the code for my GetCurrentUser() Method:

 

 

/// <summary> /// Helper method to retrieve the user object for the authenticated user. /// </summary> /// <returns>IUser</returns> public static User GetCurrentUser() { SLXUserService service = ApplicationContext.Current.Services.Get<IUserService>(true) as SLXUserService; User UserContext = service.GetUser(); return UserContext; }