The CreatorCon Call for Content is officially open! Get started here.

contract table

michelyabre
Tera Contributor

hello experts
I have a problem with the relaeted list at the contracts level.
i've written a business rule that will allow you to enter the old start date, end date and amount of a contract in the clm_contract_history table.
here's my script

(function executeRule(current, previous, prev_contract /*null when async*/ ) {

    // Add your code here
    // Vérifier si le champ a été modifié
    var numero = current.sys_id;
    var date_start = previous.starts;
    var date_end = previous.ends;
            // Récupérer l'ancienne valeur du champ
        var cost = previous.total_cost;

        var test = new GlideRecord('clm_contract_history');
        history.initialize();
        history.query();
        if (test.next()) {
            if (current.total_cost != previous.total_cost && previous.total_cost != ""){
            history.contract_id = numero;
            history.u_old_cost = cost.getCurrencyDisplayValue();
            history.starts = date_start;
            history.ends = date_end;
           
        }
        test.insert();
    else if (date_start!="" && current.starts != date_start || current.ends != date_end && previous.ends!="") {
        var history = new GlideRecord('clm_contract_history');
        history.initialize();
        history.query();
        if (history.next()) {
            history.contract_id = numero;
            history.u_old_cost = current.total_cost.getCurrencyDisplayValue();
            history.starts = date_start;
            history.ends = date_end;
           
    }
   
}
test.insert();
})(current, previous);


But my problem is that when I save it, I get 2 lines as if the modification had been made 2 times.

michelyabre_0-1718920107197.png


here's why i'm asking the expert community for help

thanks

@all 

1 REPLY 1

Bert_c1
Kilo Patron

hi,

 

these lines of code are confusing:

 

 

        var test = new GlideRecord('clm_contract_history');
        history.initialize();
        history.query();
        if (test.next()) {
You are refereing to two different objects: 'test' and 'history'. Try:
 
        var history = new GlideRecord('clm_contract_history');
        history.initialize();
        history.query();
        if (history.next()) {
 
And other places in your script that references 'test' and not 'history'.