cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

With only node id, how can I get email address in user field on document belongs to ?

bson21
9-Granite

With only node id, how can I get email address in user field on document belongs to ?

Hello

 

I would like to create trigger

in script I want to get email address in document's user field

trigger is triggered when node is changed, so I only know node id.

with this node id, I can get document's ID using API.

but I have a problem getting email address in user field on document.

 

below is my plan to getting user email address

(1)node(2nd level) ID -> (2)node(1st level) ID -> (3)document ID -> (4)user field list -> (5)user email address

I achieved only (3)

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
awalsh
17-Peridot
(To:awalsh)

The previous script assumes that the node is being edited. If that's not the case, and you just have the ID, then you can get an Issue bean for the node ID rather than getting a delta bean:

 

// var nodeBean = bsf.lookupBean("imIssueDeltaBean");
var nodeBean = server.getIssueBean(1234,["Document ID"]);

where 1234 is the node ID.

 

View solution in original post

3 REPLIES 3
awalsh
17-Peridot
(To:bson21)

You will need to get an issueBean for the document to see the user field info, then a userBean for the user to get the email address.

 

Sample script that just looks up the user email and prints to the server.log file:

var eb = bsf.lookupBean("siEnvironmentBean");
eb.setMessageCategory("GENERAL");

var server = bsf.lookupBean("imServerBean");
var nodeBean = bsf.lookupBean("imIssueDeltaBean");
var userfield="Assigned User";

var docID=nodeBean.getDocumentID();
var docBean=server.getIssueBean(docID,[userfield]);
var username=docBean.getFieldValue(userfield);

if (username != null) {
var userBean=server.getUserBean(username);
var userEmail=userBean.getEmailAddress();
eb.print("The email address for " + username + " is " + userEmail);
} else {
eb.print("The user field " + userfield + " is empty on Document " + docID);
}

I ran this as a pre-trigger with the rule "Type=Requirement", and here's the server.log output for different values of the user field:

2019-05-27 11:35:27,586 INFO  [mksis.IntegrityServer] GENERAL(5): awalsh[RMI Executor-thread-8]: Trigger "useremail.js" - The email address for awalsh is awalsh@test.com
2019-05-27 11:36:57,072 INFO  [mksis.IntegrityServer] GENERAL(5): awalsh[RMI Executor-thread-3]: Trigger "useremail.js" - The email address for business_analyst is null
2019-05-27 11:38:53,074 INFO  [mksis.IntegrityServer] GENERAL(5): awalsh[RMI Executor-thread-6]: Trigger "useremail.js" - The user field Assigned User is empty on Document 1382
awalsh
17-Peridot
(To:awalsh)

The previous script assumes that the node is being edited. If that's not the case, and you just have the ID, then you can get an Issue bean for the node ID rather than getting a delta bean:

 

// var nodeBean = bsf.lookupBean("imIssueDeltaBean");
var nodeBean = server.getIssueBean(1234,["Document ID"]);

where 1234 is the node ID.

 

bson21
9-Granite
(To:awalsh)

Thank very much

 

your advice is very helpful for me Smiley Happy

Top Tags