Catalog date variables

GayathriI748559
Tera Contributor

How to add +7 days to the catalog variable based on RITM created date

3 REPLIES 3

folusho
Tera Guru

Please see below:

    var gd = new GlideDate();
    gd.addDays(7);
    current.sys_created_on = gd;

    var gdt = new GlideDateTime();
    gdt.addDays(7);
    current.due_date = gdt;

 

Robert H
Mega Sage

Hello,

 

You can set its Default value to this:

 

javascript:gs.daysAgo(-7);

 

Important: replace the : part with an actual colon : character as shown in the screen shot:

 

RobertH_0-1746723402522.png

 

Result:

RobertH_1-1746723454943.png

 

Regards,

Robert

 

Juhi Poddar
Kilo Patron

To add +7 days to a catalog variable based on the RITM (Requested Item) created date, you'll typically use a Catalog Client Script and GlideAjax with a Script Include.

Script Include:

var RITMHelper = Class.create();
RITMHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getDueDatePlus7: function() {
        var gr = new GlideRecord('sc_req_item');
        if (gr.get(this.getParameter('sysparm_ritm'))) {
            var gdt = new GlideDateTime(gr.sys_created_on);
            gdt.addDays(7); // server-side method
            return gdt.getDate().toString(); // return only date part
        }
        return '';
    }
});

Client script:

function onLoad() {
    var ga = new GlideAjax('RITMHelper');
    ga.addParam('sysparm_name', 'getDueDatePlus7');
    ga.addParam('sysparm_ritm', g_form.getUniqueValue());
    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.setValue('u_due_date', response); // reaplace 'u_due_date' with actual variable name
        }
    });
}

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar