How to retrieve value of a variable of catalog item in widget

Madala Chaitany
Giga Guru

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.

6 REPLIES 6

Sai Kumar B
Mega Sage
Mega Sage

@Madala Chaitanya Kumar 

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');

Navya Yetukuri
Giga Contributor

I also looking for same requirement please help

 

Ahmmed Ali
Mega Sage

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

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