Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Solved! Go to Solution.
OK, I understand the use case, thanks also for sharing the script.
This is a very big one, so I don't have time to try to fix one part to explain how to do it.
What I can say is this: you do not need and should not be using the API to process Integrity items in this script.
Everything you want to do can be achieved with the java beans provided for triggers. Have a look at an example script provided on the server like "postLinkedIssue.js". I picked that one because it creates and updates items.
In it, you find code like: newIssue.setFieldValue(description, newDescription)
All the java beans you need are documented in "Event Trigger Java Documentation" on your server's home page. They can be used create items, edit rich text fields, manipulate attachments, etc.
The main one is "ScriptIssueDeltaBean", have a look at all the methods available to you there. I can see you've defined a "delta" variable, now you have to use it. Please do not use the API.
Is the JavaScript in question an Integrity server-side trigger script?
If that's the case, why use an API call? Such calls are not recommended to update items unless you really must, and know what you're doing.
You can use the usual java beans and do exactly what you describe below with the "issue delta bean".
If it's not a server-side trigger script, then I don't think your code example will work (no java packages to import). You would have to use the "real" API or web services. And then rich text fields can be tricky to manipulate that way. Can you explain your use case in more details?
Attaching javascript file as text file and yes this a scheduled trigger on the server. Search for function "UpdateIncidentTicket" and "isValidItemId"
The process is currently extracting email data from outlook exchange inbox folder and creating an Incident Ticket.
We are wanting to enhance the process for updating the existing Incident Tickets by having the user or system email the same exchange inbox folder with additional information or when someone reply's to the notifications that we update the existing Incident ticket with new information instead of creating a new Incident Ticket.
Currently getting error message
[API-issues --fields=Detailed Description ]: im: Invalid command: issues --fields=Detailed Description
OK, I understand the use case, thanks also for sharing the script.
This is a very big one, so I don't have time to try to fix one part to explain how to do it.
What I can say is this: you do not need and should not be using the API to process Integrity items in this script.
Everything you want to do can be achieved with the java beans provided for triggers. Have a look at an example script provided on the server like "postLinkedIssue.js". I picked that one because it creates and updates items.
In it, you find code like: newIssue.setFieldValue(description, newDescription)
All the java beans you need are documented in "Event Trigger Java Documentation" on your server's home page. They can be used create items, edit rich text fields, manipulate attachments, etc.
The main one is "ScriptIssueDeltaBean", have a look at all the methods available to you there. I can see you've defined a "delta" variable, now you have to use it. Please do not use the API.
Do not use the API !
Please read what I tried to explain before, the API is not the right way to write a PRE trigger.
Note the API code is commented out only the DELTA command is running
function addRelatedItem(newItemId, relatedItemId) {
try {
print("command parameters 939 : " + "relatedItemLinkField =" + relatedItemLinkField + " relatedItemId =" + relatedItemId);
delta.setRelationshipFieldValue(relatedItemLinkField, relatedItemId);
} catch (ex) {print('addRelatedItem Failed 945: ' + ex.message);}
}
So here is the next try at this(this process is a scheduled trigger that runs every 15 minutes to update information from outside of Integrity) the getIsssueBean from the manual javadocs triggers gave me the impression that this what you use to access a specific Issue
Not sure about your use case and sequence, but this is what I can offer.
You're not using the right beans. For a scheduled trigger that updates items, the sequence would be something like this:
// Initialize the environment with necessary beans
var sb = bsf.lookupBean( "imServerBean" );
//
// Get IDs of all items returned by scheduled trigger's query
var stab = bsf.lookupBean( "imScheduleTriggerArgumentsBean" );
var itemsList= stab.getIssues();
//
// Process all found items
for ( var i = 0; i < itemsList.length; i ++ ) {
//
// Get a delta bean for the item so it can be updated
var ib = sb.getIssueDeltaBean( itemsList[ i ]);
//
// Process this item, for example:
ib.setFieldValue( FieldName , FieldValue );
ib.addRelatedIssue( RelFieldName , RelFieldValue );
}
// Done
I hope this helps.