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

Thread: tasks vs changes

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    26

    Default tasks vs changes

    Im attempting to updates changes if the task risk is higher than the change risk. It works but the task needs to be saved twice to update the change record. And the risk_assessment task variable stays active into future changes. Does anyone have anythoughts to get this to work?

    function
    taskRisk()
    {
    //var MyMessage;
    //myTask = record.number;
    //MyMessage = "Hello World " + myTask + ";" + record.risk_assessment;
    //print (MyMessage);
    //MyMessage = "";
    newTask =newSCFile("cm3t");
    var RC =newTask.doSelect("number = \""+ record.number +"\"");
    //if (record.risk_assessment != "1")
    // {
    // newTask.risk_assessment = "1";
    // var RC = newTask.doUpdate();
    // MyMessage = " Updated: " + myTask + ";" + newTask.risk_assessment;
    // }
    //print(MyMessage);
    //return newTask
    //newTask = system.record.doUpdate();
    }
    functionupdateChangeRisk()
    {
    //var NewMessage
    //NewMessage = "test"
    //newTask = new SCFile("cm3t");
    //var RC = newTask.doSelect("number = \"" + record.number + "\"");
    //var newCR = new SCFile("cm3r");
    //var newTask = new SCFile("cm3t");
    //var crRisk = parseInt(record.risk_assessment);
    //var tRisk = parseInt(newTask.record.risk_assessment);
    //var tRisk = parseInt(taskRisk.newTask.risk_assessment);
    //if (crRisk < tRisk)
    // {
    // crRisk = tRisk;
    // var RC = newCR.doUpdate();
    // }
    //NewMessage = "test" + parseInt(record.risk_assessment) + parseInt(newTask.risk_assessment);
    //print (NewMessage);
    if (parseInt(record.risk_assessment) < newTask.risk_assessment)
    {
    record.risk_assessment = newTask.risk_assessment
    }
    }

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

    Default

    You have a lot commented out from these examples. I guess that while you debug so I'll comment on these things too.

    You should not use doUpdate() because that function do not check for locks. So if a user are updating the change and this function runs the updates to the change is lost.

    You should instead use doAction("save") instead and if the return code indicate locked you should schedule the update to performed later via interoperability helper script.
    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.

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    26

    Default

    The code commented out was used when building the script, it doesnt seem to be necessary anymore. Im not sure where to put the do action(). In the task or CR function. Thankyou for the tip.

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

    Default

    Then you have a problem with your functions.

    For example the objects record and newTask in function updateChangeRisk() are not defined within the function or passed as an argument so they will be null or the results will be unpredictable.
    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.

  5. #5
    Junior Member
    Join Date
    Mar 2007
    Posts
    26

    Default

    Something like this? except Im getting the same response. But the variables are working. What objects should be defined?

    Thanks for all your help

    function
    updateChangeRisk()
    {
    //var NewMessage
    //NewMessage = "test"
    //newTask = new SCFile("cm3t");
    //var RC = newTask.doSelect("number = \"" + record.number + "\"");
    //var newCR = new SCFile("cm3r");
    //var newTask = new SCFile("cm3t");
    //var crRisk = parseInt(record.risk_assessment);
    //var tRisk = parseInt(newTask.record.risk_assessment);
    //var tRisk = parseInt(taskRisk.newTask.risk_assessment);
    //if (crRisk < tRisk)
    // {
    // crRisk = tRisk;
    // var RC = newCR.doUpdate();
    // }
    //NewMessage = "test" + parseInt(record.risk_assessment) + parseInt(newTask.risk_assessment);
    //print (NewMessage);
    currentRisk = record.risk_assessment
    currentTask
    = newTask.risk_assessment
    if (parseInt(currentRisk) <parseInt(currentTask))
    {
    record.risk_assessment = currentTask
    }}

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

    Default

    Nope.

    You need to either pass the objects as arguments like this

    result = function(argument);

    function(localrecord)
    {
    }

    Or you need to define teh object and search the relevant record in the function like you have commented out

    newTask = new SCFile("cm3t");
    var RC = newTask.doSelect("number = \"" + record.number + "\"");

    Also I would advice you to use a different name than record. There are problems using that name if function is triggered by a trigger. For example use localrecord instead.
    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.

  7. #7
    Junior Member
    Join Date
    Mar 2007
    Posts
    26

    Default

    Ok now Im a little more confused. I assume I should be making all the changes in the updateChangerisk function since that is the on form I will be modifying. It will simply be reading the task record.
    But where in the code am I going to pass the objects. I continue to get errors everytime I attempt to read the task records from there.

  8. #8
    Junior Member
    Join Date
    Mar 2007
    Posts
    26

    Default

    tommy

    Thanks for your help. It took alot of fooling around and experimenting with different functions but finally got it to work. This updates the CR risk level if the task risk level is higher than the CR. Hopefully someone else can use this. Its called from the task form format control. Will be working on it so it works from the chanbge form format control too.

    function
    taskRisk()
    {
    myCR = record.parent_change;
    var msg ="Parent:"+ myCR;
    //print(msg);
    pCR =newSCFile("cm3r");
    var RC =pCR.doSelect("number = \""+ myCR +"\"");
    if ( RC == RC_SUCCESS )
    {
    if (pCR.risk_assessment < record.risk_assessment)
    {
    msg
    =" Task:"+ record.number +" P:"+ pCR.risk_assessment +" T:"+ record.risk_assessment;
    //print(msg);
    pCR.risk_assessment = record.risk_assessment;
    RC =pCR.doUpdate();
    }
    }
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

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