How to pass a value from a Widget to a Catalog item variable

MBarrott
Mega Sage

I have a custom widget which is pulling driving directions from a API and parsing it as a string to a variable. 

 

I can see that the directions are parsed correctly via console or system logs, however I now want to pass them to a text multi-line variable I have on the Catalog Item. I browsed the forums and saw some mentions of using $scope but nothing has seemed to work and I'm not familiar with AngularJS

 

What is the optimal and/or easiest way to pass this string from the widget to the catalog item variable?

1 ACCEPTED SOLUTION

@MBarrott 

something like this

api.controller = function($scope) {
    /* widget controller */
    var c = this;
    $scope.page.g_form.setValue('variableName', 1);

};

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@MBarrott 

you can use this syntax to set value in string variable from widget client controller

$scope.page.g_form.setValue('variableName', 'Your Value');

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Is any further setup required to use that? 

@MBarrott 

that's it.

what's the issue you are facing?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@MBarrott 

something like this

api.controller = function($scope) {
    /* widget controller */
    var c = this;
    $scope.page.g_form.setValue('variableName', 1);

};

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

That might have been the issue. My client controller begins with the following: 

api.controller = function() {
    var c = this;