cannot get change record sys id when created from workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 05:07 AM
Hi All,
we have a catalog item, from there we will create change request once sctask is closed complete. I have written below code. It is creating change request, but i couldn't get sys id of the change record. I need to use the change record sys id in other activity. i am not sure what i have done mistakes. can anyone please help me for debugging.
also I have tried to get change number, I am not able to get it, it is returning as undefined.
var chg = new GlideRecord('change_request');
chg.newRecord();
chg.parent = current.sys_id;
if (current.variables.risk == "true")
chg.risk = 2;
var ven_conn_type = current.variables.is_the_vendor_connectivity_type_checkpoint_client_based_vpn;
if (ven_conn_type == 'Yes') {
var std_temp = new GlideRecord('std_change_record_producer');
if (std_temp.get(gs.getProperty('fedex.firewall.sys_id.changetemplate1'))) {
chg.std_change_producer_version = std_temp.current_version;
}
chg.requested_by = current.request.requested_for;
chg.assigned_to = workflow.scratchpad.change_assignee;
if (chg.insert()) {
var attachments = new GlideRecord('sys_attachment');
if (attachments.get('table_sys_id', current.sys_id)) {
var attach = new GlideSysAttachment();
attach.copy('sc_req_item', current.sys_id, 'change_request', chg.getUniqueValue());
    }
   chg.update();
}
workflow.scratchpad.parent_chgreq = chg.sys_id;
current.comments = "Change Request-" + chg.number + " has been created for " + current.number + ".";
Thanks,
Saranya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 08:26 AM
This is not your full code is it? Because if running this:
Javascript compiler exception: missing } in compound statement (null.null.script;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 08:39 AM - edited ‎01-22-2024 08:47 AM
hi @Mark Roethof,
below is the full code
var chg = new GlideRecord('change_request');
chg.newRecord();
chg.parent = current.sys_id;
if (current.variables.risk == "true")
chg.risk = 2;
var ven_conn_type = current.variables.is_the_vendor_connectivity_type_checkpoint_client_based_vpn;
if (ven_conn_type == 'Yes') {
var std_temp = new GlideRecord('std_change_record_producer');
if (std_temp.get(gs.getProperty('fedex.firewall.sys_id.changetemplate1'))) {
chg.std_change_producer_version = std_temp.current_version;
}
}
chg.requested_by = current.request.requested_for;
chg.assigned_to = workflow.scratchpad.change_assignee;
chg.watch_list = current.watch_list;
if (chg.insert()) {
var attachments = new GlideRecord('sys_attachment');
if (attachments.get('table_sys_id', current.sys_id)) {
var attach = new GlideSysAttachment();
attach.copy('sc_req_item', current.sys_id, 'change_request', chg.getUniqueValue());
}
   chg.update();
}
workflow.scratchpad.parent_chgreq = chg.sys_id;
current.comments = "Change Request-" + chg.number + " has been created for " + current.number + ".";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 08:47 AM
Have you tried debugging when moving the code, if workflow.scratchpad.parent_chgreq does hold the change sys_id? And that only the current.comments is the issue?
I think that is correct. At least because there is no update after the current.comments etc..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 09:16 AM
yes, I have tried debugging, workflow.scratchpad.parent_chgreq is not holding sys id, getting undefined value in the logs for chg.sys_id, chg.getUniqueValue(), chg.number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 09:39 AM
When I strip your code from the parts that I cannot test, it works fine. If ofcourse I move both lines of code inside the if. And current.comments might need to be provided with a following current.update() (not sure since I don't have your setup).
So I think something else in the code is breaking it. Did you try applying log statements to debug? Or is for example the attachment correctly created?