Flow designer - Data pill values not available in script mode

AEterni
Mega Guru

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.

find_real_file.png


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.

 

 

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

16 REPLIES 16

Ankur Bawiskar
Tera Patron

Hi,

you can use f(x) script section and get the attachment and company sys_id

firmid can be fetched like this

var FirmId = fd_data.trigger.request_item.companyField.u_member_firm_id;

Similarly for attachment

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hey,

thank you, but I don't get any value. This is the script I tried:

var firmid = fd_data.trigger.request_item.core_companyField.name;
return firmid;​

I tried to export the Name of the company, but it returns an empty output

I also tried, but it didn't work.

var firmid = fd_data.trigger.request_item.companyField.name;
return firmid;

 

I am not a developer, so I really lack in such things.

Do you know if there is any documentation where I can study the syntax?

Thank you.

Hi,

script I shared should work provided you gave the correct field name for company and member firm id

var FirmId = fd_data.trigger.request_item.companyField.u_member_firm_id;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

So, just to be clear:

  • the name of the company table is "core_company"
  • the name of Firm ID field is "u_id"

The script should then be

var firmid = fd_data.trigger.request_item.core_company.u_id;
return firmid;

Correct?