How to map 'Custom with Label' field with a string field in the backend table.

Asif_Jawed
Tera Expert

I have created a 'custom with label' field named 'pick month'.

AsifJawed1_0-1688710284936.png

or

AsifJawed1_2-1688710645989.png

 

This field is connected to a widget which is coded to take input type month.

AsifJawed1_1-1688710506880.png

 

How to map this field with the backed table field type string

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Asif_Jawed 

you need to store the value of it in some hidden variable and then use that hidden variable in script to map it with target string field

you cannot directly access value of html box or any element from widget in workflow or any other script as it's in UI

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

How to do that?

 

@Asif_Jawed 

for that you need to define some onclick event on that html element and store the value inside some string variable on that catalog item

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Asif,

 

In your submit button in Service Portal, in div tag add ng-click="c.submit()"

 

In Client Script :-

var c = this;

c.submit=function(){
c.data.action = 'createRecord' ;
c.server.update();
}

 

In Server Script :-

 

data.newRec ={
pick-month: ''   // id of the field in html.
}

if(input && input.action === 'createRecord'){
createRecord(input.newRec);
}

function createRecord(rec){
var gr = new GlideRecord('table_name');
gr.newRecord();
gr.setValue('field_name in backend', rec.pickmonth);
gr.insert();
}

 

Plz Mark my Solution as Accept and helpful, If you got any help as it will help other users as well.

 

Regards,

Samaksh.