function onLoad() {
var p=g_user.getFullName();
alert(‘This is my first client Script= ‘+p);
}
function onLoad() {
if (g_form.isNewRecord()){
alert(‘This is new Record’);
}
else{
alert(‘This is not a new record’);
}
}
function onLoad() {
g_form.setReadOnly(‘u_email’,true);
g_form.setValue(‘u_description’,’hiiiiiii’);
g_form.clearOptions(‘u_category’);
g_form.getLabelOf(‘u_number’);
g_form.addInfoMessage(‘hi’);
g_form.setMandatory(‘u_first_name’,true);
g_form.setMandatory(‘u_last_name’,true);
if (g_user.hasRole(admin)){
g_form.removeOption(‘u_state’,’Maharashtra’);
}
}
function onLoad() {
if(g_form.isNewRecord()){
g_form.setVisible(“u_convert_to”,false);
}
else {
g_form.setVisible(“u_convert_to”,true);
}
}
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
var p=g_form.getReference(“u_assigned_to”).email;
g_form.setValue(“u_email”,p);
g_form.setMandatory(“u_first_name”,true);
g_form.setValue(“u_short_description”,’This is :’+g_user.getFullName());
}
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
var p = g_form.getValue(“u_assigned_to”);
var name= g_form.getReference(“u_assigned_to”);
g_form.setValue(“u_short_description”, ‘This is’+name.first_name);
alert(newValue);
alert(oldValue);
}
function onSubmit() {
//Type appropriate comment here, and begin script below
var a = g_form.getValue(“u_first_name”);
var b = g_form.getValue(“u_last_name”);
var con= confirm( ‘You Entered below datails-\n The first name is- ‘+a+’\n The last name is- ‘+b+’\n Do you confirm the details?’ );
if(con==true){
return;
}
else{
return 0;
}
}
function onSubmit() {
//Type appropriate comment here, and begin script below
var p = g_form.getValue(“u_assigned_to”);
var name= g_form.getReference(“u_assigned_to”);
g_form.setValue(“u_short_description”, name.first_name);
alert(p);
}
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
alert(sysIDs);
alert(table);
alert( oldValues);
alert(newValue);
alert(callback);
callback(saveAndClose);
}
function onLoad() {
if (g_form.isNewRecord()){
alert(‘This is new Record’);
}
else{
alert(‘This is not a new record’);
}
}
………………………………………………………………………………………………………..
function onLoad() {
if(g_form.isNewRecord()){
g_form.setVisible(“u_convert_to”,false);
}
else {
g_form.setVisible(“u_convert_to”,true);
}
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
var p=g_form.getReference(“u_assigned_to”).email;
g_form.setValue(“u_email”,p);
g_form.setMandatory(“u_first_name”,true);
g_form.setValue(“u_short_description”,’This is :’+g_user.getFullName());
}
………………………………………………………………………………………………………..
function onSubmit() {
//Type appropriate comment here, and begin script below
var a = g_form.getValue(“u_first_name”);
var b = g_form.getValue(“u_last_name”);
var con= confirm( ‘You Entered below datails-\n The first name is- ‘+a+’\n The last name is- ‘+b+’\n Do you confirm the details?’ );
if(con==true){
return;
}
else{
return 0;
}
}
………………………………………………………………………………………………………..
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.isNewRecord()){
g_form.setSectionDisplay(“closure_information”, false);
}else{
g_form.setSectionDisplay(“closure_information”, true)
}
}
………………………………………………………………………………………………………..
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue(“state”)==1){
}else{
g_form.removeOption(“state”,’1′);
}
}
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var requireOtherField = (newValue == ”);
g_form.setMandatory(‘work_notes’, requireOtherField);
}
………………………………………………………………………………………………………..
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var requireOtherField = (newValue == ”) ;
g_form.setMandatory(‘comments’, requireOtherField);
}
On Change Client Script on Caller Field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
g_form.getReference(‘caller_id’, priorityCallback);
}
function priorityCallback(caller){
if (caller.vip == ‘true’) {
g_form.setValue(“impact”,1);
g_form.setValue(“urgency”,1);
}
}
………………………………………………………………………………………………………..
Start date validation –
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
var start_date = g_form.getValue(“u_start_date”);
var end_date = g_form.getValue(“u_end_date”);
var format = g_user_date_time_format;
if (start_date != “” && end_date != “”) {
var isEndBeforeStart = compareDates(start_date, format, end_date, format);
//0 – means valid date(end date is more than start date)
//1 – means start is grater than end
if (isEndBeforeStart) {
alert(“Start date can not be grater than end date”);
g_form.setValue(“u_start_date”, ” “);
}
}
}
………………………………………………………………………………………………………..
OnChange Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ”) {
return;
}
var start_date = g_form.getValue(“u_start_date”);
var glideAjax = new GlideAjax(“ExpectedCloseDateSI”);
glideAjax.addParam(“sysparm_name”,”getStartDate”);
glideAjax.addParam(“sysparm_start_date”,start_date);
glideAjax.getXML(callBackFunction);
function callBackFunction(response){
var res = response.responseXML.documentElement.getAttribute(“answer”);
g_form.setValue(“u_expected_close_date”,res);
}
//Type appropriate comment here, and begin script below
}
Script include
ExpectedCloseDateSI
var ExpectedCloseDateSI = Class.create();
ExpectedCloseDateSI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getStartDate : function (){
var start_date_from_client = this.getParameter(“sysparm_start_date”);
var new_expected_date = new GlideDateTime(start_date_from_client);
new_expected_date.addDays(5);
return new_expected_date;
},
type: ‘ExpectedCloseDateSI’
});
Client Script: On Change of User.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == ”) {
return;
}
var name = g_form.getValue(‘user_name’);
var ga = new GlideAjax(‘ClientSideUtils’);
ga.addParam(‘sysparm_name’, ‘getUserDetails’);
ga.addParam(‘sysparm_user’, newValue);
ga.getXML(setUserDetails);
function setUserDetails(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute(“answer”);
var split = answer.split(‘#’);
g_form.setValue(’email’, split[0]);
g_form.setValue(‘department’, split[1]);
g_form.setValue(‘user_contact’, split[2]);
g_form.setValue(‘company’,split[3]);
g_form.setValue(‘region’,split[4]);
g_form.setValue(‘business_unit’,split[5]);
}
}
Server Side Script:
var ClientSideUtils = Class.create();
ClientSideUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserDetails: function() {
var usr = this.getParameter(‘sysparm_user’);
var gr = new GlideRecord(‘sys_user’);
gr.addQuery(‘sys_id’, usr);
gr.query();
if (gr.next()) {
var email = gr.email;
var dept = gr.department;
var mob = gr.mobile_phone;
var com=gr.company;
var loc=gr.location;
var bunit=gr.location.getDisplayValue()+” Business Unit”;
return email + “#” + dept + “#” + mob+”#”+com+”#”+loc+”#”+bunit;
}
},
type: ‘ClientSideUtils’
});