transform script

Priya123
Tera Contributor

am having a transform script where i update approval set Date time field type on customer project table 

basically, if the import set has values other than dates leave it blank else fill it with the date

The 1st time its happening correct (like blank when no date and date when present)

but after that if i test it by making a row blank , after a date is filled , the previous value is set and not blanking. any idea?

8 REPLIES 8

Priya123
Tera Contributor
var gdt = new GlideDateTime(source.u_opening_date);

    gs.log("GDT--> "+gdt);


    var openDate = new GlideDateTime();
        gs.log("OPEN DATE-> "+openDate);
   
    if(gdt == null || gdt == '')
    {
        openDate =  '';
        gs.log("inside null Loop-> "+openDate);
    }
    else
    {
        gs.log("inside else-> "+openDate);
        var seconds = 18*60*60;
        gdt.addSeconds(seconds);
        openDate = gdt.getValue(); // return the value to be put into the target field
        gs.log("OPEN DATE after Setting-> "+openDate);
        }

        gs.log("OPEN DATE after Setting finallllly-> "+openDate);
        return openDate;

Try:

 

var gdt = new GlideDateTime(source.u_opening_date);

    gs.log("GDT--> "+gdt);


    var openDate = new GlideDateTime();
        gs.log("OPEN DATE-> "+openDate);
   
    if(gdt == null || gdt == '')
    {
        openDate =  'NULL';
        gs.log("inside null Loop-> "+openDate);
    }
    else
    {
        gs.log("inside else-> "+openDate);
        var seconds = 18*60*60;
        gdt.addSeconds(seconds);
        openDate = gdt.getValue(); // return the value to be put into the target field
        gs.log("OPEN DATE after Setting-> "+openDate);
        }

        gs.log("OPEN DATE after Setting finallllly-> "+openDate);
        return openDate;

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Unable to format NULL using format string yyyy-MM-dd HH:mm:ss for field approval_set

Then I think you won't be able to do this using a scripted field map.

 

Use a before transform script:

 

Use target.setValue('opening_date', '') in your else, or target.setValue('opening_date', openDate) instead of return openDate


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.