- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 02:04 AM
I want to insert catalog item variable record to custom table as soon as the RITM gets created.
I am writing after BR on ritm table( its not working) for same but looking for more suggestions.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tbl1 = new GlideRecord('u_cst_account');
tbl1.query();
if(tbl1.next())
{
var rec1=tbl1.u_account_names;
if(current.variables.var_type1 == 'AST1')
{
current.variables.var_name = rec1;
tbl1.setValue(name,current.variables.var_name);
}
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 03:41 AM
Ok if its inserting of record
then you need to do 2 things
1. Make a check if same record exist
2. If Yes then ignore or If No then insert
var recinsert = new GlideRecord('u_cst_account');\
recinsert.addQuery('columnename',current.variables.var_name);//add here column name against which you want to check
recinsert.query();
if(!recinsert.next()) //If no record found
{
var recinsertnow = new GlideRecord('u_cst_account');
recinsert.initialize();
recinsert.setValue(name,current.variables.var_name);
recinsert.insert();
}
Hope this helps
Thank you
Prasad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 07:20 AM
Did you mapped the variables correctly? Can you show me your script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 12:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 08:28 AM
Great Solution!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 02:23 AM
Hi,
This line:
tbl1.setValue(name,current.variables.var_name);
name needs to be 'name' as it is a field.
correct script line:
tbl1.setValue('name',current.variables.var_name);
I also recommend adding tbl1.update();
If this solved your issue please mark my answer correct.
Thanks
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 02:43 AM
Hi,
I misread your initial question.
To insert a record you must use the below script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tbl1 = new GlideRecord('u_cst_account');
tbl1.query();
if(tbl1.next())
{
var rec1=tbl1.u_account_names;
if(current.variables.var_type1 == 'AST1')
{
current.variables.var_name = rec1;
var tbl1Insert = new GlideRecord('u_cst_account');
tbl1Insert.initialize();
tbl1Insert.setValue'(name',current.variables.var_name);
tbl1Insert.insert();
}
}
})(current, previous);