Update custom table with variable values from Catalog item

Angshuman3
Mega Guru

Hi All,

Is it possible to create a new record in a custom table with the Variable values whenever a catalog item request is Completed? What should be the practice that we should follow.

For example, there are 2 variables (Name, Age)
If Name - ServiceNow; Age - 10

When the request gets completed, this exact values should get copied to a new record in the custom table in ServiceNow.

Thanks.
Angshuman

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Anshuman,

you can do this provided the variables don't increase in future for that catalog item; because in that case then you will have to create field on the custom table

you can have business rule on ritm table with condition as state is completed and have sample script below

create an array of json object which will tell which field of custom table is mapped to which variable of catalog item

then iterate over the json object and insert record

var obj = '[{"field":"age","variable":"age"},{"field":"name","variable":"name"}]';

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Can this approach be same for Multi Row Variable Set variables and its values?

Can't we use Run Script Activity from the workflow itself post completion of SCTASK?

Thanks,
Angshuman

naveen14
Kilo Guru

Hi Anshuman,

Yes,Is it possible to create a new record in a custom table with the Variable values whenever a catalog item request is Completed.

i am also doing the same task by complete the task the catalog item variables should be store in the custom table

1.You should create a custom table with each datatype is string.

2.By script include you can call each variables to the table by using workflow

test:function(current){
        var t= new GlideRecord('sc_req_item');
        t.addQuery('sys_id',current);
        t.query();
        gs.log();
        var ab;
        if(t.next()){
            //ab=t.number;
            var ty=new GlideRecord('u_task');
            ty.initialize();
            ty.u_number=t.number;

ty.insert():

keep this code in script include and call all the data

Mark Correct if this solves your issue and also mark Helpful if you get my solution is correct

Thanks

Naveen B