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 05:14 AM
Hi there,
It looks correct behavior to me if the last 2 lines don't provide any information using chg.
Why? Because it's outside the if statement. Inside the if statement, for example you are using chg.getUniqueValue() > that will most likely work because its inside the if statement.
So this is by your own design that its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 07:30 AM
hi @Mark Roethof,
I have moved those 2 lines to inside if, but still i am getting undefined value.
Thanks,
Saranya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 07:35 AM
Please share your updated code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 08:20 AM - edited ‎01-22-2024 08:20 AM
hi @Mark Roethof,
below is the updated code, i have noticed that chg.getUniqueValue() is also not returning record sysid. getting undefined value.
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());
    }
workflow.scratchpad.parent_chgreq = chg.sys_id;
current.comments = "Change Request-" + chg.number + " has been created for " + current.number + ".";
   chg.update();
}
Thanks,
Saranya