Skip to main content
1-Visitor
August 27, 2019
Solved

Ability to extract issue information inside a JavaScript api call

  • August 27, 2019
  • 1 reply
  • 7233 views
Would like to know if any one has tried creating a JavaSript routine to extract information from an issue to update with addition information;
Like retrieve the Rich text information from an Incident Ticket and the old and new add additional details together then update the field with new merged information.
 
i.e.
 
EXTRACT OLD DATA
var command = new Packages.com.mks.api.Command("im", "issues --fields='Detailed Description'");
        command.addSelection(UpdateItemId);
        var response = apiBean.executeCmd(command);
 
UPDATE WITH OLD AND NEW MERGED TOGETHER
var issuesCommand = new Packages.com.mks.api.Command("im", "editissue");
issuesCommand.addOption(new Packages.com.mks.api.Option("UpdateIssue", "Detail Description" + "=" + AdditionalDetailDescription));
            issuesCommand.addSelection(UpdateItemId);
        var response = apiBean.executeCmd(issuesCommand);
 
Best answer by LLawton

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.

1 reply

16-Pearl
August 27, 2019

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?

 

jsummers1-VisitorAuthor
1-Visitor
August 27, 2019

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.   

 

So the process would be;

  • Check to see if it is an Incident Ticket by testing for specific information in the subject line to verify that it is an existing ticket. (That part is working.)

 

  • I'm able to add the update and/or reply email as an attachment but does not work will with rich text information.

 

  • So my goal is to update the current "Detail Description" with the additional information by
    •    Extracting the current value and adding the new information from the body of the email 
    •    Update the issue's "Detail Description" with old and new information merged together. 

Currently getting error message

    [API-issues --fields=Detailed Description ]: im: Invalid command: issues --fields=Detailed Description 

16-Pearl
September 10, 2019

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.