Populate source fields from task in expence line .

SandeepKSingh
Kilo Sage

I have a requirnmnet to"Populate source fields from task" onChange of Field Task in fm_expense_line table.

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hello,

 

Use the below :-

 

RaviGaurav_0-1724335543999.png

RaviGaurav_1-1724335559021.png

Code :-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || (g_form.getValue('parent') != '' && g_form.isNewRecord())) {
      return;
   }
   
   if (g_scratchpad.active == undefined || g_scratchpad.active == 'false') {
      g_scratchpad.active = 'true';
      var record = g_form.getReference('task')
      var task = new GlideRecord(record.sys_class_name);
      task.get(record.sys_id);
     
      var ci = new GlideRecord('cmdb_ci');
      ci.get(task.cmdb_ci);
      g_form.setValue('ci', ci.sys_id);
      g_form.setValue('asset', ci.asset);
      g_form.setValue('cost_center', ci.cost_center);
      g_form.setValue('contract', '');
      g_form.setValue('source_id', '');
     
      if (task.caller_id != undefined)
         g_form.setValue('user', task.caller_id);
      else if (task.requested_by != undefined)
         g_form.setValue('user', task.requested_by);
      else
         g_form.setValue('user', '');
     
      g_scratchpad.active = 'false';
   }
}
 
--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

1 REPLY 1

Ravi Gaurav
Giga Sage
Giga Sage

Hello,

 

Use the below :-

 

RaviGaurav_0-1724335543999.png

RaviGaurav_1-1724335559021.png

Code :-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || (g_form.getValue('parent') != '' && g_form.isNewRecord())) {
      return;
   }
   
   if (g_scratchpad.active == undefined || g_scratchpad.active == 'false') {
      g_scratchpad.active = 'true';
      var record = g_form.getReference('task')
      var task = new GlideRecord(record.sys_class_name);
      task.get(record.sys_id);
     
      var ci = new GlideRecord('cmdb_ci');
      ci.get(task.cmdb_ci);
      g_form.setValue('ci', ci.sys_id);
      g_form.setValue('asset', ci.asset);
      g_form.setValue('cost_center', ci.cost_center);
      g_form.setValue('contract', '');
      g_form.setValue('source_id', '');
     
      if (task.caller_id != undefined)
         g_form.setValue('user', task.caller_id);
      else if (task.requested_by != undefined)
         g_form.setValue('user', task.requested_by);
      else
         g_form.setValue('user', '');
     
      g_scratchpad.active = 'false';
   }
}
 
--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/