Populate Catalog Item Variable Values via Script Include

jiral
Giga Sage

We have a custom table with the following tables:

Active Job Code Job Title Catalog Item Variables
true A3124 Senior Analyst SharePoint 'variables':{ "vURL": "https://sharepoint.com/teams/eshare/_layouts/15/people.aspx?",
"AccessLevel": "1",
"AccessTypes": "Contributor",
"Groups":"8b7eacef1b3681509157b95e034bcb2d,c08ea8631b7681509157b95e034bcb60"}
true A3124 Senior Analyst MS Teams 'variables':{ "AccessType": "Analyst, IT",
"Region": "Asia/Pacific",
"Groups":"8b7eacef1b3681509fsdfs34bcb2d,c08ea8631b76646131319e034bcb60"}

When a new user is created with the given job code, create a new request using the catalog items in the given record and populate the catalog item variables with the defined values in the "Variables" column. 

I have been trying to get the variable values populated, but ritms are coming in as blank.

5 REPLIES 5

Anirudha1
Giga Contributor

Hi,

Can you please share a screenshot of the custom table record and the script you are trying to write to have this work done?

Hello,

 

Basically, I just need the variable showing under item substituted with the "Variables" in the example given in my original post. Do you have any recommendation?

 

				var cart = new sn_sc.CartJS();
				var item =
					{
						'sysparm_id': catitem,
						'sysparm_quantity': '1',
						'variables':{
							"vCallerId":newhire,
							"vURL": "https://sharepoint.com/teams/esite/_layouts/15/people.aspx?MembershipGroupId=110",
							"vAccessRequestIsTo": "1",
							"vAccessTypes": "vContributor"
						}};
				var cartDetails = cart.addToCart(item);
				gs.log(JSON.stringify("Cart Details :" + cartDetails));
		}

Here's the screen capture of the variables after submission:

find_real_file.png

 

Here's the script that I've been using:

var OnBoardAutomationV2 = Class.create();
OnBoardAutomationV2.prototype = {
	initialize: function() {},
	onBoardUser: function(currentObject) {

		var newhire = String(currentObject.u_requested_for);
		var jobCodeValue = String(currentObject.u_requested_for.u_job_code);

		var reqitems = new GlideRecord('u_onboarding_item');
		reqitems.addQuery('active',true);
		reqitems.addQuery('u_job_code',jobCodeValue);
		reqitems.query();
		while(reqitems.next())
		{
			var cat_item = reqitems.u_catalog_item;
			var RITMVals = reqitems.u_variables.toString(); //u_variables contains the pre-constructed string containing the catalog item and its variables. The variables are showing as blank.
				
			var json = new JSONParser();
			var object = json.parse(RITMVals);
 
			var cart = new sn_sc.CartJS();
			var item = object;

			cart.addToCart(item);
			cart.checkoutCart();
			gs.info(JSON.stringify(cartDetails));
		}

	},


	type: 'OnBoardAutomationV2'
};

Anirudha1
Giga Contributor

Hi,

Can you try using the following code in your background scripts and check

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
 //add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('4054428fdb151f0097679ec6db9619c0', 1);

//fill in the variables on the request item form
cart.setVariable(item,"u_requested_for", "e80edd6edbec6bc097275e25ca9619a4"); 
cart.setVariable(item,"contact_number", "0");
cart.setVariable(item,"assignment_group", "87ec1c342b2e71406c487fb5a8da1524"); 
cart.setVariable(item,"application_service", "cdedfbcedb0f9744c291c170ba9619a7");
cart.setVariable(item,"short_description", email.subject);
cart.setVariable(item,"description", email.body_text);
var rc = cart.placeOrder();

You can use gs.print(rc.toString()); to check for the Sys ID of the generated request and check if you are able to get the variables populated. This works for me. Then implement the same in your main code.