- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 05:08 AM
Hello All,
I have recently discovered that it is not possible to drag and drop data from the data pill values of the flow inside a script.
I hope you can help me with the following requirement.
This is the script we are using
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var output = {"FirmId":46,"EncryptedPassword":encodedpw,"AttachmentId":"b16829cd87d541903c1da6c73cbb350d"};
return output;
I would like to get
- the "FirmId" from the company table and
- the sysID of the attachment
For the "FirmId" we usually dot.walk using the data pill values (see image below), but it is not possible when are in script mode.
For the sysID of the attachment, do you know how I can get it?
The final script should look like this one.
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var FirmId = xxx
var AttachmentId = xxx
var output = {"FirmId":46,"EncryptedPassword":encodedpw,"AttachmentId":"b16829cd87d541903c1da6c73cbb350d"};
return output;
Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 01:05 AM
Hi,
you want attachment sys_id for the RITM record?
if yes then you need to query sys_attachment with current ritm sys_id
like this
var ritmSysId = fd_data.trigger.request_item.sys_id;
var attachmentID;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", ritmSysId);
gr.query();
if (gr.next()) {
attachmentID = gr.getUniqueValue();
}
return attachmentID;
So your final code when I combined above script is this
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var companyID = fd_data.trigger.request_item.company.u_id;
var output = {};
var ritmSysId = fd_data.trigger.request_item.sys_id;
var attachmentID;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", ritmSysId);
gr.query();
if (gr.next()) {
attachmentID = gr.getUniqueValue();
}
output["FirmId"] = companyID.toString();
output["EncryptedPassword"] = encodedpw.toString();
output["AttachmentId"] = attachmentID.toString();
return output;
Please mark my response as correct and close the thread
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 08:42 AM
Hi,
the field on RITM table which refers core_company is company
so give this
var firmid = fd_data.trigger.request_item.company.u_id;
return firmid;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 09:03 AM
Indeed, this one works and returns the value.
var companyID = fd_data.trigger.request_item.company.u_id;
return companyID;
If I try to add this to the original script I get I get this error message
{ "serialization error": "No serializer found for class com.glide.db.datamodel.ShortTableName and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.HashMap["FirmId"]->com.glide.script.glide_elements.GlideElementNumeric["ed"]->com.glide.db.ElementDescriptor["shortTableName"])"}
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var companyID = fd_data.trigger.request_item.company.u_id;
var output = {"FirmId":companyID,"EncryptedPassword":encodedpw,"AttachmentId":"b16829cd87d541903c1da6c73cbb350d"};
return output;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2022 08:33 PM
try to send the object like this
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var companyID = fd_data.trigger.request_item.company.u_id;
var output = {};
output["FirmId"] = companyID.toString();
output["EncryptedPassword"] = encodedpw.toString();
output["AttachmentId"] = "b16829cd87d541903c1da6c73cbb350d";
return output;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 12:56 AM
Hey,
it works. Thank you very much for your help.
Is it too much to ask if you can help me with that last piece of the script to find the sys_id of the attachment?
I know that all attachments are saved in the sys_attachment table. I am trying this script, but it returns empty value
var attachmentID = fd_data.trigger.request_item.attachment.table_sys_id;
return attachmentID;
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 01:05 AM
Hi,
you want attachment sys_id for the RITM record?
if yes then you need to query sys_attachment with current ritm sys_id
like this
var ritmSysId = fd_data.trigger.request_item.sys_id;
var attachmentID;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", ritmSysId);
gr.query();
if (gr.next()) {
attachmentID = gr.getUniqueValue();
}
return attachmentID;
So your final code when I combined above script is this
var pwvalue = new GlideappMaskedQuestion().decode(new GlideEncrypter().decrypt(fd_data._1__get_catalog_variables.password));
var encodedpw = new GlideappMaskedQuestion().decode(new GlideEncrypter("xxx").encrypt(pwvalue));
var companyID = fd_data.trigger.request_item.company.u_id;
var output = {};
var ritmSysId = fd_data.trigger.request_item.sys_id;
var attachmentID;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", ritmSysId);
gr.query();
if (gr.next()) {
attachmentID = gr.getUniqueValue();
}
output["FirmId"] = companyID.toString();
output["EncryptedPassword"] = encodedpw.toString();
output["AttachmentId"] = attachmentID.toString();
return output;
Please mark my response as correct and close the thread
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader