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 an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to get correct DocumentID right after Requirement creation in a trigger?

AN_10548594
6-Contributor

How to get correct DocumentID right after Requirement creation in a trigger?

Hello team,

How to get correct DocumentID right after Requirement creation in a trigger?

 

001.png

 

very simple code returns 0

 

theRequirementDocumentID = delta.getDocumentID();
print("*** Requirement Document ID for " + delta.getType() + " " + delta.getID() + " is: " + delta.getDocumentID());

After second Text edit it goes ok though.

But I need to get DocID right after Requirement creation.

Problem in trigger Rule definition?

Now set as Type = New [Requirement]

Many thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions

There is possibility to modify item in post trigger by using CLI commands instead of trigger API.
It's not very sophisticated and recommended and you need to be careful with that but sometimes there is no other way to achieve the goal.
Here is an example of command execution in script, you can find more options in the documentation.
 

 

var apiSession = environmentBean.createAPISessionBean();
var runner = apiSession.createAPICommandRunnerBean();
runner.setCommand("im", "<command>");
runner.execute();

 

 

Using "Document ID" field with versioning is quite risky as it could be not available for versioned item (usually it's there only for live items).

View solution in original post

6 REPLIES 6

Hi @AN_10548594,

 

"Document ID" field is being calculated after creation of an item.

Try to execute your logic in a "Post" trigger which will run after your new requirement is saved to DB.

Hi pal,

Thanks for help!

I can't use post trigger as i'm going to modify my requirement.

I'm trying to set computed upstream and downstream object names in custom fields to make them look nicer in Excel.

Anyway in my case the solution could be the fact that a computed number should have a version number as a postfix. That means to make it all work user should hit F3 on content to create a mior or major version. After that all triggers are ok to run.

Regards,

 

There is possibility to modify item in post trigger by using CLI commands instead of trigger API.
It's not very sophisticated and recommended and you need to be careful with that but sometimes there is no other way to achieve the goal.
Here is an example of command execution in script, you can find more options in the documentation.
 

 

var apiSession = environmentBean.createAPISessionBean();
var runner = apiSession.createAPICommandRunnerBean();
runner.setCommand("im", "<command>");
runner.execute();

 

 

Using "Document ID" field with versioning is quite risky as it could be not available for versioned item (usually it's there only for live items).

Thanks a lot again!

Very usefull and seems like a solution for my case.

Will check and let you know,

PS. Hi )))

 

Hi again,

And this is what TS says about this:

"The document ID is stored in a field named Document ID. When a new item is created, the value of the Document ID field hasn't been commited yet during the PRE trigger phase. 

To get the document ID of a newly created item in a PRE Trigger, use the getNewFieldValue("Document ID") method on the ScriptIssueDeltaBean."

Regards

And this is wrong answer from TS

 

Top Tags