How to read a field value in workflow

Mike160
Kilo Contributor

I have a workflow with a Notification Activity. I want it to send the email to the user who created the record that started the workflow. The table, u_infosec_risk_review has a column titled usubmitter. usubmitter has a default that populates the column with the sysid of the user who created the record.

I've searched for code to get the value in the Advanced Script and haven't found anything that's worked for me. I have tested it by hard-coding the sysid in the Advanced Script and it worked fine, so my issue is getting the actual value and not the assignment to the To: field.

Here's what I currently have:

// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
var gr= new GlideRecord('u_infosec_risk_review');

answer=gr.getValue('usubmitter');

 

find_real_file.png

Can anyone point me in the right direction on this? 

 

Thanks,

Mike

 

1 ACCEPTED SOLUTION

No problem.  What you could do is:

1. replace the "Notification" activity with a new "Create Event" activity

find_real_file.png

You can create a new Event name by clicking on the magnifying glass to the right of the field, click on the "New" button and then fill out the form.  I highly suggest using a "u." prefix to avoid any issues with SN creating the same one in the future.

Use the following code in the "Parameter 1" field so we can include the recipient in the event:

(function() {
	// return the value to use for Parameter 1
	return current.getValue("usubmitter");
}());

For now you can just disconnect the "Notification" activity so you don't lose anything:

find_real_file.png

 

2. create a new Notification record.  On the "When to send" tab, set the "Send when" dropdown to "Event is fired" and then select the new Event name you just created

find_real_file.png

On the "Who will receive" tab, select the "Event parm 1 contains recipient" check box:

find_real_file.png

You may have to click on the "Advanced view" Related Link in order to see it:

find_real_file.png

OR, using the "Users/Group in fields" field, you could select the appropriate field that contains the recipient, in your case the "usubmitter" field.  A no-code alternative where you would not need any code in the "Create Event" activity.

Now you have a Notification that can be easily maintained and any running workflows would get the updated one right away.

View solution in original post

5 REPLIES 5

dvp
Mega Sage
Mega Sage

You can select usubmitter field in To field on approval user