- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 02:46 AM
I want to insert a new record to a table , with the value interchanged between two reference field
Eg : Screenshot (A)
In my related incident table ( embedded list in Incident form where I am adding existing incident ), once a record is inserted with Parent and incident Ticket Number and Link type , plese refer screenshot A
I want to insert another record where the Parent value copies Incident Ticket Number value , Incident ticket number copies Parent field value
and Linky type if preceeding then get converted to Successive and Vice Versa, See Screenshot (B)
Below is the Before insert and Update BR i wrote on Incident table :
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_related_incident_emb');
gr.addQuery('parent', current.number);
gr.query();
if(gr.next())
{
gr.initialize();
gr.u_parent == gr.u_incident_ticket_number;
gr.u_incident_ticket_number == gr.u_parent;
gr.insert();
}
})(current, previous);
Can somebody advise what is wrong or the correct approach ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 04:53 AM
Hi
Sorry to mention this but the complete logic was provided by me and you marked someone's response as correct. there could be some changes but still the logic matters.
even below code works without using setValue/getValue.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_related_incident_emb');
gr.addQuery('parent', current.number);
gr.query();
if(gr.next())
{
var inc = gr.u_incident_ticket_number.toString();
var par = gr.u_parent.toString();
var type = gr.u_link_type;
gr.initialize();
gr.u_parent =inc;
gr.u_incident_ticket_number =par;
if(type == 'succesisve')
gr.u_link_type = 'preceeding';
else
gr.u_link_type = 'succesisve';
gr.insert();
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 04:01 AM
Hi
Try this
Modify field names and values accordingly.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_related_incident_emb');
gr.addQuery('parent', current.number);
gr.query();
if(gr.next())
{
var inc = gr.u_incident_ticket_number;
var par = gr.u_parent;
var type = gr.u_link_type;
gr.initialize();
gr.u_parent =inc;
gr.u_incident_ticket_number =par;
if(type == 'succesisve')
gr.u_link_type = 'preceeding';
else
gr.u_link_type = 'succesisve';
gr.insert();
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 04:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 04:53 AM
Hi
Sorry to mention this but the complete logic was provided by me and you marked someone's response as correct. there could be some changes but still the logic matters.
even below code works without using setValue/getValue.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('u_related_incident_emb');
gr.addQuery('parent', current.number);
gr.query();
if(gr.next())
{
var inc = gr.u_incident_ticket_number.toString();
var par = gr.u_parent.toString();
var type = gr.u_link_type;
gr.initialize();
gr.u_parent =inc;
gr.u_incident_ticket_number =par;
if(type == 'succesisve')
gr.u_link_type = 'preceeding';
else
gr.u_link_type = 'succesisve';
gr.insert();
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 05:03 AM
Hi Rohila,
Yes , i was confused which one to mark as correct both helped me in some way !
But logic was yours only ..!! Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 05:14 AM
ThankYou.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP