Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 2 of 2

Thread: variable inconsistency in JavaScript on Trigger

  1. #1
    Junior Member
    Join Date
    Dec 2007
    Location
    Johannesburg
    Posts
    4

    Default variable inconsistency in JavaScript on Trigger

    Greetings All,
    I am having a problem with some JavaScript code that I am trying to run from a trigger. For some odd reason it appears that my declared variables are being set to null after they get used once. My code is below.
    Code:
    var newRec = record;
    var oldRec = oldrecord;
    //MSG4504: (Mail the Contact) Interaction Closed
    if (newRec.open=="Closed") {
    var interaction = newRec.incident_id;
    var contact = newRec.contact_name;
    system.library.MtlNotificationLibrary.generateMessage("MSG4504",interaction,"MSG4504",contact,"individual");
    interaction = newRec.incident_id;
    print("interaction: "+interaction);
    var infoRep = newRec.alternate_contact;
    system.library.MtlNotificationLibrary.generateMessage("MSG4510",interaction,"MSG4510",infoRep,"individual");
    }
    
    My first call to the script library yields the result that I want, it creates an HTML message. However, the second call yeilds nothing as the 'interaction' variable gets set to null after the first script library call.

    You will notice the first two lines create variable to hold record and oldrecord as I have encountered this variable anomaly before. It seems as though once you pass a variable off to a script library, it cannot be used in the trigger again. It is really frustrating.

    Has anyone ever encountered this before?

    Thanks,
    Warren

  2. #2
    Administrator tommy's Avatar
    Join Date
    Nov 2001
    Location
    Copenhagen
    Posts
    4,272

    Default

    My first suggestion is that you create your function in the scriptlibrary and then calls the function from the trigger passing record and oldrecord as parameters.

    In the script do NOT use the same names but call them for example localrecord and localoldrecord.
    Best regards Tommy
    Blog - - ITIL certified - Accredited Integration Specialist – HP OpenView Service Management

    Want to keep this site alive? Consider making a donation. Click here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts