How to retrieve value of a variable of catalog item in widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 11:15 PM
Hi,
I am new to widgets creation. I have created a widget to display the dynamic link on the catalog form.
Could you please help me to retrieve the value of variable and pass it in the dynamic link.
HTML:
<div>
<!-- your widget template -->
<a href = "/src?p={{c.populateRole()}}" target="_blank">Click Here</a>
</div>
Server script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.role = getRole();
function getRole(){
var persona = $scope.page.role;
var assGrps = new GlideRecord("table_name");
assGrps.addQuery('persona', persona);
assGrps.query();
if(assGrps.next()){
var secGrp = assGrps.security_group;
var role = new GlideRecord("sys_group_has_role");
role.addQuery("group", secGrp);
role.query();
if(role.next()){
return role.sys_id;
}
}
}
})();
Client Controller:
api.controller=function() {
/* widget controller */
var c = this;
c.populateRole = function(){
c.roleSysyId = c.date.role;
return c.roleSysId;
};
};
Thanks in advance.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 11:23 PM
In your client controller, you can use the below to access the variable, Make sure $scope is set as a parameter in your client controller function as below
api.controller = function($scope) {
//Use the below syntax to access catalog variable value
}
$scope.page.g_form.getValue('variable_name');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 04:48 AM
I also looking for same requirement please help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 05:16 AM
Hello,
You can read catalog item variable value in client controller as below:
add $scope in first line of client controller as below:
api.controller=function($scope)
and to read variable value, you can user $scope.page_g_form.getValue("VARIABLE_NAME");
Also, you need to call c.populateRole() function in client script and then send the role value to Server side to get the required return value to populate in HTML.
Please refer below URLs which has good explanation about communicating between client and server side in a widget.
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2022 08:10 PM
Can you share the URL,i want to display client controller data in server script so I can glide that data return from client side in portal, please send code related to this scenario