Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Nickel Contributor
Posts: 47
Registered: ‎05-25-2011

Dojo Lookup widgets - how to prepopulate a selected value?

have a question. Hopefully someone can give me an answer or point me to existing code examples on how to solve this.

 

I'm creating a User lookup from javascript like this:

 

              var lookupConfig = {
                structure: [
                    {
                        cells:
                            [
                                {
                                    name: nlsResources.txtName,
                                    field: 'UserInfo.UserName',
                                    sortable: true,
                                    width: "400px",
                                    editable: false,
                                    propertyType: "System.String",
                                    excludeFromFilters: false,
                                    defaultValue: ""
                                }
                            ]
                    }
                ],
                gridOptions: {
                    contextualCondition: function () {
                        return 'Type ne 5 and Type ne 8 and Type ne 6';
                    },
                    contextualShow: '',
                    selectionMode: 'single'
                },
                storeOptions: {
                    resourceKind: 'users',
                    include: ['UserInfo'],
                    sort: [{ attribute: 'UserInfo.UserName' }]
                },
                isModal: true,
                preFilters: [],
                returnPrimaryKey: true,
                dialogTitle: nlsResources.txtSelectUser,
                dialogButtonText: nlsResources.txtOK
            };
            this.lkpUser = new Lookup({
                id: 'lkpUser',
                readonly: false,
                config: lookupConfig
            });
            //dojo.connect(this.lkpUser, 'onChange', this, '_userChanged');
            dojo.place(this.lkpUser.domNode, this.contentPaneLkpUser.domNode, 'only');

Now, lets say I have a userId 'UXXXXXXXXXXX', and I would like this lookup to be prepopulated with that user as the default selected object when it is created. Is there a way to do that?

 

Thanks for your help,

Nico.

Highlighted
Copper Contributor
Posts: 10
Registered: ‎08-12-2011

Re: Dojo Lookup widgets - how to prepopulate a selected value?

I'm looking into how to write widgets, too, and I'd like to find out if anyone knows where to find documentation on how to pull data from the database.

 

However, one thing you can do is to look at the Today's Activities widget. It has code to pull in Activities based on the current user's ID. This comes in the html section with code like:

 

   var _currentUserId = Sage.Utility.getClientContextByKey('userID') || '';
   _currentUserId = _currentUserId.trim();

 

(The trim is because this value comes back padded with at least one space in some instances.)

 

I need more information to use this further, but if you are looking to get the current user, then I think this code will give it to you.