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

@MBarrott 

then use the syntax I shared and it should work fine

api.controller = function($scope) {
    /* widget controller */
    var c = this;
$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

@MBarrott 

Hope you are doing good.

Did my reply answer your question?

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

Thank you @Ankur Bawiskar! $scope not included in the function param was the issue.