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

Nick Parsons
Mega Sage

@MBarrott  Can you share what you've tried and any error message you received so we don't suggest things that you've done already? The approach you mentioned with using $scope seems correct. Also I assume this widget is added to your cat item via the "custom" variable?

Hi @Nick Parsons 

 

Yes I'm using Custom with label right now. Maybe I was using $scope incorrectly. I had a few instances where the console reported back that $scope was not defined. 

Shivalika
Mega Sage

Hello @MBarrott 

 

Have you made use of "Custom" variable type in catalog item ? You can further give the name of the widget there. We have been collecting data in one of the catalog items following this approach and its likely to work.

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hi @Shivalika 

Yes, I'm currently using Custom with label.