The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Work in client script with getReference dotwalking

gabriel_sk
Tera Contributor

Hello team,

First of all sorry for the newby question. I will try to explain what I am trying to achieve:

I have created a new table where to perform a ticket assessment. In the form I use, I enter the ticket number and then all info regarding the specific ticket appears (only some fileds). So far all good... but I have 2 specific issues:

1 I would like the ticket that have been already assessed not appearing anymore in the reference field I use to browse to select an incident. I have thought of this solution:
I added a field to the incident entry called Incident reviewed, and placed it in the ticket review form... so when this box is tick, the specific incident will not appear anymore (via filtering the reference field).

I would like to use a client script to make this automatic... ex. when the Incident number get populated the incident reviewed tick box should get tick.

In client script I use something link this:

var test = g_form.getReference('u_inc_number').u_reviewed;

g_form.setValue(test, true);

Nothing happen   is there a way to get it working? I tried also using

document.getElementById('u_tickets_review.u_inc_number.u_reviewed').checked = true;

no luck!

Notice: the reference field on the table is u_inc_number which is pointing to the incident table. Via u_inc_number, I added to the form via dotwalking the other incident table fields such as u_reviewed.


2 I have also another element giving me issues, in this case the Additional Comments (a journal field in the incident table). Instead of displaying just its content it add also the time stamp and the creator:

"06/14/17 09:43:54 - System Administrator (Additional comments)"

This could be fine but when I save the form, the system recognize it as a new comment in the incident and add it

I thought of copying the content of additional comment in a newly created column of the ticket review table... but so far I was unable to get the content copied still using getReference...

Nothing appear.

Do you know what I am doing wrong?

or is there is a way not to avoid the incident table to be updated when i save the incident review for that specific additional comment field?

Thank you so much for all your support:)

5 REPLIES 5

Chuck Tomasi
Tera Patron

You might be interested in taking a look at michael.ritchie's solution called "getReferenceAdvanced" that makes it easy to grab dot-walked fields from a server call.



getReferenceAdvanced, g_form.getReference and GlideAjax Alternatives


Hey Chuck,



thanks for the reply, I have checked the link. That seems more for the cases the field you are pointing to is a reference filed on the other table. In my case the field is not referenced in the incident table.



The weird part of it is that I can get it working if for ex. I want to copy the content of the short description...


var test = g_form.getReference('u_inc_number').short_description;


g_form.setValue("u_my_field", test);



but the same does not work if I point to additional comments


var test = g_form.getReference('u_inc_number').comments;


g_form.setValue("u_my_field", test);



Thx:)


Comments are stored in a journal field. They are treated different. As a result, you may need to use a GlideAjax call to the server.   A bit more complex, but it gives you total control.



On the server side script you retrieve the journal field information using the getJournaleEntry() method, but it all starts with your client script calling the server to ask for retrieved information.



Docs: Client Scripts


Docs: GlideForm


Docs: GlideAjax


Client Script Best Practices - ServiceNow Wiki      


Hey Chuck,



I got it sorted out with a Business rule   was tricky but in the end worked out



Thank you for your suggestions!