The CreatorCon Call for Content is officially open! Get started here.

Clear value on reference field

sowmyarajaram
Kilo Guru

Hello All,

I have reference field by name field1 and 2 other fields by name field2 and field3. The values on field2, field3 are based on the reference field1. what I'm trying to achieve is if I have a value on field1 as xxxx, it sets field2, field3. later when I try to edit value on reference field1 to something else, i want the fields2, field3 to show no data on it (while i'm trying to change value on field1) 

Field1 = reference field

Field2, Field 3 = text field

 

Any help?

 

Sowmya

10 REPLIES 10

Cool,

Please close the thread by marking the appropriate response correct/helpful.

Thanks,

Anurag

-Anurag

Hi,

Just checking to see if this is answered or you looking for some more information?

-Anurag

-Anurag

Kieran Anson
Kilo Patron

Are field2 and field3 pulling data that originates from the field1 record? I'm not a fan of duplicating data when you could just display those reference field values on the form via dot walking. What is the purpose of pulling the text in this way?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Are these fields also dependend on each other?

If not, you could simply set up a UI Policy. No code needed. UI Policy triggered on field 1, UI Policy Actions for your other fields with the checkbox "Clear the field value" checked. That;s all.

No scripting needed. No client scripts whatever, just UI Policy.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

@sowmyarajaram 

Assuming you must be using onChange Client Script with getRefence() callback OR GlideAjax

Your onChange should look like this

It should clear field 2 and field 3 when Field1 is cleared out

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

if(newValue == ''){

g_form.clearValue('field2Name');

g_form.clearValue('field3Name');

}

// your logic here to set the values

}

Regards
Ankur

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