Populate GlideDateTime from Client Script using scratchpad

SNAdmin47
Kilo Sage

This is specifically for the population of the 'due_date' field on a RCA problem task when created from a problem record via Interceptor. 

 

  1. On problem, click 'New' in Problem Task related list
  2. This triggers the Interceptor asking which asks for confirmation of which task to create. Selecting RCA opens the problem task with a type of 'Root Cause Analsysis'
  3. Some fields are not auto-populated from the parent. 

To achieve this I've created the following display BR to populate the scratchpad:

 

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

	// Add your code here
	var gdt = new GlideDateTime();gdt.addDays(5);gdt.getDisplayValue().toString;
	g_scratchpad.gdtScratch = gdt;
	g_scratchpad.short_descriptionScratch = 'Analyze Root Cause for Incident ' + current.problem.number;
	g_scratchpad.descriptionScratch = 'Please analyze the root cause for incident ' + current.problem.number;
	g_scratchpad.companyScratch = current.problem.company.sys_id;
	//gs.log('The value of gdtScratch is ' + g_scratchpad.gdtScratch);

})(current, previous);

This works fine the logging confirms the date time being provided is correct, e.g., The value of gdtScratch is 2025-06-18 11:28:26. 

 

Then I have the following client script to populate the problem task onLoad, but the field is populated with [object Object] instead of a date/time 5 days in advance. 

function onLoad() {
    //Type appropriate comment here, and begin script below

   if (g_form.getValue('company')== "") {
        g_form.setValue('company', g_scratchpad.companyScratch);
        g_form.setValue('short_description', g_scratchpad.short_descriptionScratch);
        g_form.setValue('description', g_scratchpad.descriptionScratch);
		g_form.setValue('due_date', g_scratchpad.gdtScratch);
    }
}

What am I doing wrong here? I've tried different variants of getDisplayValue, toString, etc., in the BR but it still gives me the same field population of [object Object]. When I populate that field using a BR it works just fine, so I'm obviously doing something wrong with the scratchpad usage. 

 

Any input would be greatly appreciated, many thanks in advance. 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @SNAdmin47 ,

update your BR like this and try

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

    // Add your code here
    var gdt = new GlideDateTime();
    gdt.addDays(5);
    g_scratchpad.gdtScratch = gdt.getDisplayValue();
    g_scratchpad.short_descriptionScratch = 'Analyze Root Cause for Incident ' + current.problem.number;
    g_scratchpad.descriptionScratch = 'Please analyze the root cause for incident ' + current.problem.number;
    g_scratchpad.companyScratch = current.problem.company.sys_id;
    //gs.log('The value of gdtScratch is ' + g_scratchpad.gdtScratch);

})(current, previous);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

2 REPLIES 2

Chaitanya ILCR
Kilo Patron

Hi @SNAdmin47 ,

update your BR like this and try

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

    // Add your code here
    var gdt = new GlideDateTime();
    gdt.addDays(5);
    g_scratchpad.gdtScratch = gdt.getDisplayValue();
    g_scratchpad.short_descriptionScratch = 'Analyze Root Cause for Incident ' + current.problem.number;
    g_scratchpad.descriptionScratch = 'Please analyze the root cause for incident ' + current.problem.number;
    g_scratchpad.companyScratch = current.problem.company.sys_id;
    //gs.log('The value of gdtScratch is ' + g_scratchpad.gdtScratch);

})(current, previous);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Thanks @chaitk , that really helped and I think that's the quickest correct answer I've ever had on the community. Thanks very much, really appreciate it. 😁