How to display custom variables in case details through workflow script

Community Alums
Not applicable

Hi Team,
I have created one child RITM ticket using workflow (Run script) for creation of variables to display in case details section, I have used below script

var sysId = req.insert();     // child RITM sys id
var rec = new GlideRecord('question_answer');
    rec.initialize();
    rec.table_name = 'sc_req_item';
    rec.table_sys_id = sysId;
    rec.value ='Monitering service' ;
    rec.setDisplayValue('question', 'TouchPoint Name');   //
    rec.order = 100;
    rec.insert();

And this is not working what I am expecting

Note: Variables which need to display in case detail those are not present in form

Swapna9_0-1708603313703.png



Could you please let me know the solution, please share any script which will work for this scenario.

Thank you in Advance




1 ACCEPTED SOLUTION

is this working form background scripts?

 

Can you try the below to see if this works

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();
-Anurag

View solution in original post

11 REPLIES 11

Anurag Tripathi
Mega Patron
Mega Patron

You have to do it along the ritm, and to do so you basically need to submit a new cart.

try this in a background script and if ti works well you can add this in your workflow

 

var cart = new sn_sc.CartJS();
var item = {
	'sysparm_id': '0d081123db11230096a99ee4db961972',
	'variables': {
		'carrier': 'at_and_t_mobility',
		'data_plan': '500MB',
		'duration': 'eighteen_months',
		'color': 'slate',
		'storage': 'sixtyfour'
	}
};
var cartDetails = cart.orderNow(item);
gs.info(JSON.stringify(cartDetails, null, 4));

 

-Anurag

Community Alums
Not applicable

Hi @Anurag Tripathi 

I have used this code, it's creating multiple RITM's but not showing any variable in case details

can you show the code you used? 

-Anurag

Community Alums
Not applicable
@Anurag Tripathi 
var cart = new sn_sc.CartJS();
 var item = {
 'sysparm_id': 'e31e5b40db411b80f1fbfe18bf961946',
 'variables': {
      'pull_request_url': 'Test123',
       
 }
 };
 var cartDetails = cart.orderNow(item);
gs.info(JSON.stringify(cartDetails, null, 4));