Issue on Field Style

amlanpal
Kilo Sage

Hi All,

I'm facing a typical issue on Field Style. Hope you can provide solution to this. Here is the issue:

I have applied same field style to both Caller field and Assigned to field on Incident form to display the VIP icon beside the field if the selected user is VIP. The Field Style applied on Caller field is an OOB one. Just created the same Field style for Assigned to field and modified the Field name & Value to Assigned to in order to apply the same style on the field.

Surprisingly, the Assigned to Field Style is not working on form view. Whereas, I can see the style applied to both the fields on List view. Please see the screenshots below.

The Field style for Assigned to field is given below. The only relevant changes are there for Caller field Field style is there and working fine:

Table: Incident

Field name: Assigned to

Value: javascript:current.assigned_to.vip == true;

Style:background-image: url('images/icons/vip.gif');

background-repeat: no-repeat;

background-position: 98% 5px;

padding-right: 30px;

Any help will be highly appreciated!

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Field style doesn't work usually on form layout if the value of field style contains 'javascript:' (Dynamic condition). If you can hard code some condition, it might work well.


View solution in original post

12 REPLIES 12

Hi Amlan,



Have we answered your question on this one?



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


Anyone been able to get this client script working on a createNow/scoped application?

 

I see this error:

onChange script error: TypeError: $ is not a function function () { [native code] }

 

In the script i have replaced the lines with 'incident.caller_id' for 'x_spog_travel_traveller.u_traveller'

Inspected the field the names were actually to check the id names, they are:

label.x_spog_travel_traveller.u_traveller

sys_display.original.x_spog_travel_traveller.u_traveller

 

function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.x_spog_travel_traveller.u_traveller');
var callerField = $('sys_display.x_spog_travel_traveller.u_traveller');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('u_traveller', vipCallerCallback);
}

function vipCallerCallback(caller) { // **my field name is Passenger, does this need to be passenger? tried but didn't work either
var callerLabel = $('label.x_spog_travel_traveller.u_traveller').down('label');
var callerField = $('sys_display.x_spog_travel_traveller.u_traveller');
if (!callerLabel || !callerField)
return;

//check for VIP status
if (caller.vip == 'true') { // **
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";

callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}

Swapnil Bhakar1
Mega Guru

Hi Amlan Pal,



Write onchange client script:



Table : Incident


Type: onChange


Field Name: Assigned to



Script: Copy and paste below script,don't make any changes



function onChange(control, oldValue, newValue, isLoading) {


  var callerLabel = $('label.incident.assigned_to');


  var callerField = $('sys_display.incident.assigned_to');


  if (!callerLabel || !callerField)


  return;



  if (!newValue) {


  callerLabel.setStyle({backgroundImage: ""});


  callerField.setStyle({color: ""});


  return;


  }


  g_form.getReference('assigned_to', vipCallerCallback);


}




function vipCallerCallback(caller) {


  var callerLabel = $('label.incident.assigned_to').down('label');


  var callerField = $('sys_display.incident.assigned_to');


  if (!callerLabel || !callerField)


  return;



  //check for VIP status


  if (caller.vip == 'true') {


  var bgPosition = "95% 55%";


  if (document.documentElement.getAttribute('data-doctype') == 'true')


  bgPosition = "5% 45%";



  callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });


  callerField.setStyle({color: "Red"});


  } else {


  callerLabel.setStyle({backgroundImage: ""});


  callerField.setStyle({color: ""});


  }


}



Hope it will help you.



Regards,


Swapnil



PS: Hit like, Helpful or Correct depending on the impact of the response