auto populate incident field on incident task table

pvv1045330
Tera Contributor

Hi All,

 

I have a requirement to populate field values from incident to incident task,

 

In Incident form i am having (business_service=abc,  service_offering=wer, cmdb_ci=cde, short_description=test)

these fields i want to populate on incident task while creating new incident task from incident.

 

For  this requirement I'm using below code it's populated  all values except 'service_offering' filed value .

Can any one help me on that how can I auto populate all values

Script Include:

taskinfo: function(){
        var info = this.getParameter('inc_id');
        var gr = new GlideRecord("incident");
        gr.get(info);
        var ITbs = gr.getValue('business_service');
        var ITso = gr.getValue('service_offering');
       var ITsd = gr.getValue('short_description');
        var response = {};
        response.ITbs = ITbs;
        response.ITso = ITso;     
        response.ITsd = ITsd;
        return JSON.stringify(response);
    },
 
Client script: 
var incident_sys_id = g_form.getValue('incident') ;
    if(incident_id != ''){
        var ga = new GlideAjax('name');
        ga.addParam('sysparm_name'"taskinfo");
        ga.addParam('inc_id', incident_id); 
        ga.getXMLAnswer(function(answer){ 
            var response = JSON.parse(answer);
            g_form.setValue('business_service', response.ITbs) ;
            g_form.setValue('service_offering', response.ITso) ;
 
can you correct me what I miss on script for populated all value.
 
Thanks,
    
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@pvv1045330 The script appears to be correct. However, on the incident_task from there is a reference qualifier defined on the Service offering field which only let select those service offering where the parent is value populated on the Business Service field.

Screenshot 2023-10-05 at 12.04.54 AM.png

In your script, please make sure to populate only those Service offering which are children of Business Service populated on the Service field.

View solution in original post

9 REPLIES 9

If there are more than one values then you will have to use List type field rather than a reference type field for Service offering.

No we can't change the field type, issue is it's populated value on service offering field and got cleared 

is there any dictionary override issue?, 

Amit Gujarathi
Giga Sage
Giga Sage

HI @pvv1045330 ,
I trust you are doing great.
Please find the below corrected code for the same

Script INclude:

 

var YourScriptIncludeName = Class.create();
YourScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    taskinfo: function(){
        var info = this.getParameter('inc_id');
        var gr = new GlideRecord("incident");
        if (gr.get(info)) {
            var ITbs = gr.getValue('business_service');
            var ITso = gr.getValue('service_offering');
            var ITsd = gr.getValue('short_description');
            var response = {};
            response.ITbs = ITbs;
            response.ITso = ITso;     
            response.ITsd = ITsd;
            return JSON.stringify(response);
        }
        return null;
    },
    type: 'YourScriptIncludeName'
});

 

 

Client Sxript

var incident_id = g_form.getValue('incident');
if (incident_id) {
    var ga = new GlideAjax('YourScriptIncludeName'); // Replace with the actual name of your Script Include
    ga.addParam('sysparm_name', "taskinfo");
    ga.addParam('inc_id', incident_id); 
    ga.getXMLAnswer(function(answer) { 
        var response = JSON.parse(answer);
        g_form.setValue('business_service', response.ITbs);
        g_form.setValue('service_offering', response.ITso);
        // Add any other fields you want to set here
    });
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,

No Luck, still I,m getting same issue,

When I comment //g_from.setValue('business_service', response.ITbs);, Then service offering value will be populate but service filed is empty.

 

I want both filed will be populated . 

Pavan Kumar28
Tera Contributor

Hi @pvv1045330

Did you get any solution for this ?

Regards,
Pavan.