Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Copper Super Contributor
Posts: 172
Registered: ‎07-06-2010

Applying Picklist Names Dynamically in Mobile

[ Edited ]

First, yes I've posted about 5 times now. I apologize, but the nature of the issue wasn't apparent until now.

 

That being said...

 

I am trying to extend the Opportunity Edit view to include a Picklist control. This Picklist control needs to have a dynamically set picklist source. The source name is returned as a part of a JSON string, along with some other data, from a web service. I am calling the web service using dojo.xhrPost.

 

I am having a lot of problems figuring out how, and where, to put the function that calls the web service.

 

When I put the method call in my Create Layout override, the form layout is rendered BEFORE the call to xhrPost. So when the form loads it's too late to apply the value that's returned.

 

Anywhere else I put it in applicationmodule.js fails. I can't seem to get the variable scope right to get the returned data to add another picklist element to the default layout. So it either fails completely or it just renders the page with a single picklist element and forgets the default  layout. Specifically, in the load function argument in xhrPost the variable for CreateLayout loses scope and nothing's appended to it.

 

registerOpportunityCustomizations: function() {

 var editLayout = Mobile.SalesLogix.Views.Opportunity.Edit.prototype.createLayout;

{
                createLayout: function () {
                    var editViews = editLayout.apply(this, arguments) || [];
                   

                    editViews.splice(1, 0,
                    {
                        title: 'mytitle',
                        label: 'My Label',
                        name: 'Field Name here',
                        property: 'Property here',
                        type: 'decimal',
                        required: true
                    });

 

                    dojo.ready(function () {

                        dojo.xhrPost({
                            url: 'https://myservice.svc/mymethod',
                            postData:dojo.toJson({
                                'opportunityId': 'oppidhere',
                                'loggedInUserId': 'useridhere'
                            }),
                            headers: {
                                "Content-Type": "application/json"
                            },
                            load: function (slxProxyResponse) {
                                var jsonResponse = dojo.fromJson(slxProxyResponse);

 

                                spPicklist = jsonResponse.PicklistName;
                                spEnablePickList = jsonResponse.ShouldEnablePicklist;

 

                                //EDITVIEWS is out of scope and does not get changed if I try to splice an element in
                            },
                            error: function (slxProxyResponse) {
                                alert("Could not load  " + slxProxyResponse);
                            }
                        });
                    });
                   
     // SPPICKLIST IS NOT IN SCOPE HERE, default layout is loaded.
                    return editViews;
                }

 }

 

What is the best way for me to get this done? Thanks.

Highlighted
Bronze Super Contributor
Posts: 129
Registered: ‎06-09-2009

Re: Applying Picklist Names Dynamically in Mobile

Have you looked at how this is done on the Account Edit view?

 

The SubType picklist is based on the Selected value of the Type picklist.

 

 

This may be a good example to review.

 

 

 

 

Raul A. Chavez
http://raul.chavez.com
http://www.crmbi.com
Highlighted
Copper Super Contributor
Posts: 172
Registered: ‎07-06-2010

Re: Applying Picklist Names Dynamically in Mobile

[ Edited ]

Thanks for your reply Raul.

 

That almost gets me there, except I am getting undefined as the returned result. It appears I still have a variable scope issue.

 

I revamped the function so that it returns a string. It does not need to accept parameters. But while the alert message shows the right picklist name, I still get undefined returned from the function.

 

getPicklist: function () {
            var returnedPicklist;
            dojo.ready(function () {
                dojo.xhrPost({
                    url: 'myurl',
                    postData: dojo.toJson({
                        'opportunityId': 'myid',
                        'loggedInUserId': 'myuserid' //App.context.user.$key
                    }),
                    headers: {
                        "Content-Type": "application/json"
                    },
                    load: function (slxProxyResponse) {
                        var jsonResponse = dojo.fromJson(slxProxyResponse);

                        returnedPicklist = jsonResponse.PicklistName;
                        var spEnablePickList = jsonResponse.ShouldEnablePicklist;


                        if (!returnedPicklist) {
                            returnedPicklist = "defaultpicklist";
                        }
                        alert(returnedPicklist);
                        return returnedPicklist;
                    },
                    error: function (slxProxyResponse) {
                        alert("Could not load picklist " + slxProxyResponse);
                    }
                });
            });
           
     
        }

 

Highlighted
Copper Super Contributor
Posts: 172
Registered: ‎07-06-2010

Re: Applying Picklist Names Dynamically in Mobile

So after digging some more and using dojo.deferred I still cannot get this variable right.  It continues to come back as undefined. However, the alert shows the correct value.

 

I've tried placing a variable in outer scope but that didn't work.

 

 getPicklist: function () {
            var xhrArgs = {
                url: 'myUrl',
                postData: dojo.toJson({
                    'opportunityId': 'myOppId',
                    'loggedInUserId': 'myUserId' //App.context.user.$key
                }),
                headers: {
                    "Content-Type": "application/json"
                }
            }
            var deferred = dojo.xhrPost(xhrArgs);
            deferred.then(
                        function (data) {
                            var jsonResponse = dojo.fromJson(data);

                            picklistName = jsonResponse.PicklistName;
                            

                            if (!picklistName) {
                                picklistName = "defaultPickListName";
                            }
                            return picklistName;
                        },
                    function (error) {
                        alert("Could not load picklist " + error);
                    });
            ;
            //return picklistName; -- null
        },