How to create a record in custom table with the service catalog variables and workflow

Community Alums
Not applicable

I have a service catalog item which contains list fields. In the catalog item there are two variables of type list collector they are Application and Role. 

My requirement is to create create a new record in User Application table(custom table) when the catalog item was submitted. If I select two applications and two roles 4 records should be created in the user application table.

Can anyone suggest script that I have to use in workflow.

 

Thank you.

3 REPLIES 3

BharathChintala
Mega Sage

@Community Alums  in workflow add run script  activity and write this code

var use = current.variables.requested_for;

var app = current.variables.application;

var applen = app.join(',');

var rol = current.variables.roles;

var rollen = rol.join(',');

for(var i=0; i>applen.length;i++){

var cs = new GlideRecord("youcustomtablename");

cs.initialize();

cs.user = use;

cs.application=applen[i];

cs.insert();

}

for(var k=0; k>rolelen.length;k++){

var cs1 = new GlideRecord("youcustomtablename");

cs1.initialize();

cs1.user = use;

cs1.roles=rollen[k];

cs1.insert();

}

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Community Alums
Not applicable

It is not working @BharathChintala 

I have reference fields in the custom table. My requirement is to populate the list collector values of catalog item to reference field in custom table.

 

 

@Community Alums  I have sent script based on screen shot u have attached. Please check backend names of variables and fields 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala