Highlighting new and updated calls in colour

tech_tc
Mega Contributor

Hi All

Im trying to highlight all newly updated calls (non itil role) in light blue, so that they are easy to spot by our users that have the itil role. Then once updated by a itli role user the call should immediately remove the blue background.

I've seen something quite close to what I want in a blog by MB Incident updates - colouring in the number, but I need the update to be triggered from a caller sending return update via email.

The table name I'm going to use as an e.g. is u_special.

I'd appreciate some help with the BR script. I want it simply to run after an update to the call and write a string into a field.


The business rule

name will be brHighlight

Active, Advanced, insert, update, query are all ticked

When: After

Condition: none


Script:

\\ i want to highlight new calls and calls updated by a caller and script should set string value "Special Caller" into a field called 'Update Type' on the u_special table that will be hidden. The Assign to should not trigger as their updates never need to be highlighted.

if (current.operation() == 'insert' && current.comments.changes() != 'current.assigned_to') {

                              setDisplayValue('Special Caller', current.u_update_type);

}

Style Module

Value: javascript:current.u_update_type == "Special Caller"

Style: background-color:lightblue

Field Name: Updated

Table Name: u_special

Table

Table Name: u_special

Field Column Name: u_update_type

Field Label Name: Update Type

Thanks TC

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Tony,



All right, lthat clarifies things.


This form is for the table "u_special" and u_special extends Task. Incident (literally the table named incident) has no part in this.


callHighlight.PNG



You want the value of u_update_type on the u_special table to change as stuff happens.


The Caller is stored in the u_caller field, the Assigned to person is in the assigned_to field.



To clarify some of my earlier comments: sys_updated_by exists on the record, whether you show it on the form or not. It's a base system field, and is on every table. We can ignore that though, and use the gs.getUserName() call if this will be updated interactively (not via an import or integration, but by a person actually filling in a form and clicking a button to submit it).



Similarly, assigned_to is on the Task table, which is why your u_special inherits it. The caller_id field I mentioned in an earlier post is on the Incident table, which is why you don't have that on your u_special table- you don't inherit it, because you extend Task, not Incident.



Given your answers, you need a condition like this:


current.u_caller.hasValue()



All that condition does is make sure the Business Rule runs only if the Caller is actually populated. This should be a Before Insert/Update rule on the u_special table.



To make your script work, we use the more complicated version I posted before, adjust for the understanding that this not on the Incident table (or an extension of it) but instead is for this totally different u_special table which extends Task.



//who is making this update right now  


var updater = gs.getUserName();  


 


//reset the update type - this makes the value blank unless the


//updater is the Assigned to user or the Caller


current.u_update_type = "";  


 


//do the assigned_to logic  


if(current.assigned_to.hasValue() && current.assigned_to.user_name == updater)  


      current.u_update_type = "Commented";  


 


//do the Special Caller logic  


if(current.u_caller.hasValue() && current.u_caller.user_name == updater)  


      current.u_update_type = "Special Caller";



If you leave this as-is, then the u_update_type will have 3 possible values:


  1. Empty because the person doing the update or insert is neither the Caller nor the Assigned to user
  2. Commented because the person doing the update is the Assigned to user
  3. Special Caller because the person doing the update is the Caller


If you want there to be only two possible values- Commented and Special Caller, then remove line 06 and Line 09. Then it will always be either Commented or Special Caller, so long as the Caller field is actually populated.


View solution in original post

19 REPLIES 19

Hi


I do not have an update_by custom field.


When I get back in 3hrs or so. I'll change to sys_updated_by.



I did try your 3rd scenario and it did remove 'Special Caller' and replace with 'Assign to'. But when the caller updated the call the 'Special Caller' value did not populate the Update Type field.




TC


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Tony,



Then you need to figure out what the updater name is, and comapre that to the current.caller.user_name value. Why aren't they the same? That'll tell you what you need to fix.


I'm a bit puzzled now.



the form has a field labelled:'Caller' element:u_caller on table u_special. It is a reference type.



Also the updater name appears to be sys_updated_by as Cory said, but none of these values work.


The values i can get working are 'caller' and updated_by.



the code i have working in part is below this for the 'Special Called' write. But this writes the value for everyone included the assign to and the highlight never goes off.



callHighlight4.PNG


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Tony,



OK, let's sort this out.



  • This is question deals with Incident records.
  • You have a field called u_caller- that's a custom field (as in, it doesn't ship Out-of-Box), and it is a reference to the table u_special (another custom table).
  • You have a field named sys_updated_by which contains the user_name of the user who last updated the record.
  • You are using updated_by in your conditionals, but you don't actually have a field named "updated_by" on this table.
  • You have a custom field name "u_update_type" which is a String field.
  • You want the "u_update_type" to have the value "Special Caller" if the person who updated the record last is also the person who is the Caller for the record.
  • If the user who updated the record last is not the caller, the "u_update_type" field should be blank.


You have 2 Caller fields- the one that is there by default (caller_id) which is a reference to the sys_user table, and the custom one (u_caller). First lets sort that out:



  1. What is the purpose of the custom Caller field (u_caller)?
  2. What kind of data is stored in the table it is a reference to (u_special)?
  3. When you say you want to base this special logic on the Caller for the incident, do you mean the person in the caller_id field, or the person represented by the record in the u_caller field?


You mentioned before that you want to clear the "u_update_type" field if the person doing the update is the assigned_to user.


  1. What if the person doing the update is neither the assigned_to user nor the caller?
  2. What if the value is empty at the time the non-assigned_to user updates the incident?
  3. What if the caller and the assigned_to person are the same, and that person updates the record? Which wins (is it highlighted or not?)


If you can answer these 6 questions, we can fix you up.


Thanks Cory


Lots of things wrong with the points listed. my fault, sorry. This is a project i inherited and dont know all the correct terms yet. i added my answers to end of your points.



  • This is question deals with Incident records. Yes but for a custom app which is an extension of the Task table by looks of things.
  • You have a field called u_caller- that's a custom field (as in, it doesn't ship Out-of-Box), and it is a reference to the table u_special (another custom table). u_caller is a custom field on this custom call logging form which is on same table as u_special, but it reference the USER table i believe.
  • You have a field named sys_updated_by which contains the user_name of the user who last updated the record. I do not have a field named sys_updated_by on the form. I have a normal Update button to click after a change to the Additional Comments has been made. When looking at the debug logs I saw 'sys_updated_by' mentioned and thought this was the term needed when asked whats doing the updating. My error.
  • You are using updated_by in your conditionals, but you don't actually have a field named "updated_by" on this table as far as i am aware. On the business rule script section the FIELD dot walking options does show a 'updated by' (current.sys_updated_by) however ive not added a field to the form called 'updated by'.
  • You have a custom field name "u_update_type" which is a String field. Correct
  • You want the "u_update_type" to have the value "Special Caller" if the person who updated the record last is also the person who is the Caller for the record. Correct
  • If the user who updated the record last is not the caller, the "u_update_type" field should be blank. Correct

You have 2 Caller fields- the one that is there by default (caller_id) which is a reference to the sys_user table, and the custom one (u_caller). First lets sort that out:


  1. What is the purpose of the custom Caller field (u_caller)? On this form i only have 1 field for holding the username. It is called 'Caller' element:u_caller on table u_special. It is a reference type callHighlight.PNG
  2. What kind of data is stored in the table it is a reference to (u_special)? Not sure i understand. The Caller field just holds name of caller. The form collects data similar to an incident\request would.
  3. When you say you want to base this special logic on the Caller for the incident, do you mean the person in the caller_id field, or the person represented by the record in the u_caller field? As in the picture above. The callers name is 'test' If 'test' updates the call the call goes light blue. If the Assigned to user shown above called 'tester' updates the call it removes the value 'Special Caller' and this removes the light blue highlight.

You mentioned before that you want to clear the "u_update_type" field if the person doing the update is the assigned_to user.


  1. What if the person doing the update is neither the assigned_to user nor the caller? Should add the value 'Commented' in the u_update_type field. This is the catch all value that will trigger a different colour style.
  2. What if the value is empty at the time the non-assigned_to user updates the incident? If this is the caller the value should be 'Special Caller', if not it should be 'Commented'
  3. What if the caller and the assigned_to person are the same, and that person updates the record? Which wins (is it highlighted or not?) The idea is to alert the Assigned to person to respond to a caller's request in a timely manner. If the Assigned to and Caller are the same, then clear the value just the same as when an Assigned to updates a call. so Assigned to wins.


If you can answer these 6 questions, we can fix you up.