Client-Server call in ServiceNow / Ajax Call / Asynchronous Call
AJAX (asynchronous JavaScript and XML) is a group of interrelated, client-side development techniques used to create asynchronous Web applications.
AJAX enables web applications to send and retrieve information to and from a server in the background, without impacting the user experience with the displayed web page.
GlideAjax:
The GlideAjax class allows the execution of server-side code from the client. GlideAjaxcalls pass parameters to the script includes, and, using naming conventions, allows the use of these parameters.
Using GlideAjax:
· Initialize GlideAjax with the name of the script include that you want to use.
· When creating the script include, you must set the name field to be exactly the same as the class name.
· When creating the script include, you must select the Client callable check box.
· Specify the parameter sysparm_name. GlideAjax uses sysparm_name to find which function to use.
· Any extra parameters may be passed in, all of which must begin with sysparm_. Avoid using predefined parameter names:
o sysparm_name
o sysparm_function
o sysparm_value
o sysparm_type
· Code is then executed with the getXML() or getXMLWait() functions.
Example of asynchronous GlideAjax call
Client Side:
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', "Bob");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); }
Server Side Code:
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() { return "Hello " + this.getParameter('sysparm_user_name') + "!"; } ,
_privateFunction: function() { // this function is not client callable
}
});
Note: You must set the name of the script include to HelloWorld.
- · The sys_script_include code must extend the AbstractAjaxProcessorclass and be client-callable.
- · Function names starting with "_" are considered private and are not callable from the client.
- · Avoid overriding methods of AbstractAjaxProcessor, including initialize. While it is possible to invoke methods of your superclass object which you have overridden, it is complicated and best avoided altogether.
Settimeout / Sleep / wait in ServiceNow
setTimeout in ServiceNow
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == oldValue){
return;
}
window.setTimeout(Test,4000);
}
function Test(){
// do your stuff here alert('Wait for 4 Seconds.');
var caller = g_form.getReference('<field_name>');
}
Note: You should always use setTimeout(Test,4000) instead of setTimeout(Test(),4000);
Sleep in ServiceNow
Note : We cant user gs.sleep function in scooped application it has to be used in non-scooped application
sleep: function (duration) {
gs.sleep(duration);
},
ServiceNow OOB Regex Validation for Currency || Email || IP address || Letter || Mac address || Number || URL
As we are using Madrid version of ServiceNow. I have come across one OOB feature of ServiceNow in Madrid for validating below
Currency || Email || IP address || Letter || Mac address || Number || URL
We have a table in ServiceNow called Questions Regular Expression “question_regex”. Which store the regular expression in record format. See below.
Once we create a record in Questions Regular Expression “question_regex” table we can put that validation while creating variable in Catalog item.
See below: This works on Single line text field.
No more writing lengthy script for validation.
Below are the Regex validation we can utilize
- Currency ($)
^\$[0-9]*\.[0-9]{2}$
- Currency (€)
^\€[0-9]*\.[0-9]{2}$
- Email address
^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
- IBAN
^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$
- IP address
^\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b$
- Letter (A-z)
^[A-Za-z]*$
- Mac address
^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$
- Zip Code (NL)
^[1-9][0-9]{3}[\s]?[A-Za-z]{2}$
^\$[0-9]*\.[0-9]{2}$
- Currency (€)
^\€[0-9]*\.[0-9]{2}$
- Email address
^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
- IBAN
^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$
- IP address
^\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b$
- Letter (A-z)
^[A-Za-z]*$
- Mac address
^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$
- Zip Code (NL)
^[1-9][0-9]{3}[\s]?[A-Za-z]{2}$
Reference :
Custom Currency field Validation
Use Below script on change of field value
This script will help you to restrict end user to provide currency value in "$0.00" format
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var cost_field = g_form.getValue('cost_field');
cost_field = cost_field.trim();
// first character should be dollar sign
var firstChar = cost_field.substring(0, 1);
if (firstChar != '$') {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// characters after the $ sign should be numerics
var cost_fieldType = isNaN(cost_field.substring(1));
if (cost_fieldType == true) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// entered value should have a decimal point
var num = cost_field.substring(1);
if (num.indexOf('.') == -1) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// there must be 2 digits only after the decimal
var decNum = num.substring(num.indexOf('.') + 1, num.length);
if (decNum.length != 2) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
}
This script will help you to restrict end user to provide currency value in "$0.00" format
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var cost_field = g_form.getValue('cost_field');
cost_field = cost_field.trim();
// first character should be dollar sign
var firstChar = cost_field.substring(0, 1);
if (firstChar != '$') {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// characters after the $ sign should be numerics
var cost_fieldType = isNaN(cost_field.substring(1));
if (cost_fieldType == true) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// entered value should have a decimal point
var num = cost_field.substring(1);
if (num.indexOf('.') == -1) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
// there must be 2 digits only after the decimal
var decNum = num.substring(num.indexOf('.') + 1, num.length);
if (decNum.length != 2) {
alert("Please enter cost_field in $0.00 format");
g_form.setValue("cost_field", oldValue);
return;
}
}
Start and End Data validation according to Data format ServiceNow
Start Date Validation :
On Change Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '') {
var dFormat = g_user_date_format;
var tFormat = g_user_date_time_format;
var today = getDateFromFormat(formatDate(new Date(), dFormat), dFormat);
var sDate = getDateFromFormat(g_form.getValue('start_date'), dFormat);
if (today > sDate) {
alert(getMessage("Select date in the future"));
g_form.setValue('start_date', '');
}
}
}
End Date Validation :
On Change Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('start_date') != '') {
var dFormat = g_user_date_format;
var tFormat = g_user_date_time_format;
var end = getDateFromFormat(g_form.getValue('end_date'), dFormat);
var today = getDateFromFormat(formatDate(new Date(), dFormat), dFormat);
var sDate = getDateFromFormat(g_form.getValue('start_date'), dFormat);
if (today > end) {
alert(getMessage("Desired End Date has to be a date in the future"));
g_form.setValue('end_date', '');
} else if (sDate != '' && end < sDate) {
alert(getMessage("End date should not be before Start date"));
g_form.setValue('end_date', '');
}
} else {
g_form.setValue('end_date', '');
alert(getMessage('First please select Start Date Of Limit Change'));
}
}
ServiceNow Best Practice :
Attachment script Attachment Mandatory ---
function onSubmit() {
if (g_form.getValue('non_tracked_devices') == 'Yes') {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must add an attachment before submitting this request.");
return false;
}
}
}
//Script to Delete multiple record
var psc = new GlideRecord('<table_name>'); //Make sure table name is correct
psc.addEncodedQuery('sourceISNOTEMPTY');// Encoded Query or Filter if any required
psc.addQuery('sourceISNOTEMPTY');//Query or Filter if any required
psc.setLimit('10'); //Limit number of records
psc.setWorkflow(false); //Turn off business rule or notifications
psc.deleteMultiple();
//On Change Client script Example ... Disable or Enable the form
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var u1 = g_form.getValue('sitescope_manager'); //optional
g_form.addInfoMessage('Please wait while fetching Server Name');
g_form.getFormElement().disable();
var links = g_form.getFormElement().getElementsByTagName("a");
for ( i=0;i<links.length;i++)
{
links[i].hide();
}
var ga = new GlideAjax('Sitescope');
ga.addParam('sysparm_name','sitescope');
ga.addParam('sysparm_sitescope_manager',u1); //optional
ga.getXML(FolderFetch);
}
function FolderFetch(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "start")
{
g_form.showFieldMsg('remote_server_name','There is some Congestion in the Network. Please try again Later','error');
}
else
{
var outputval=answer;
var arr=outputval.split("\n");
var k=0;
while(k!=arr.length)
{
g_form.addOption('remote_server_name', arr[k],arr[k]);
k++;
}
}
g_form.clearMessages();
g_form.getFormElement().enable();
var links1 = g_form.getFormElement().getElementsByTagName("a");
for ( i=0;i<links1.length;i++)
{
links1[i].show();
}
}
//How to setup OAuth2 authentication for RESTMessageV2 integrations
//Find Duplicate record in table with filed value :
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('cmdb_ci_hardware');
gaDupCheck1.addAggregate('COUNT', 'serial_number');
gaDupCheck1.groupBy('serial_number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.serial_number.toString());
}
gs.print(dupRecords);
//Script to delete duplicate records:
var dup = new GlideAggregate('dscy_router_interface');
dup.groupBy('mac_address');
dup.query();
while(dup.next()) {
var dup1 = new GlideRecord('dscy_router_interface');
dup1.addQuery('mac_address', dup.mac_address);
dup1.query();
dup1.next();
while(dup1.next())
dup1.deleteRecord();
}
//CI Asset Synchronization useful scripts
var serialNum = [”SE415WS47”, ”VMware-42 26 87 93 04 f8 e6 15-9c 43 e6 c2 0e 76 4f 55”,];
for (var i = 0; i < serialNum.length; i++) {
var grCI = new GlideRecord("cmdb_ci_hardware");
grCI.addEncodedQuery('sys_class_name=cmdb_ci_computer');
grCI.addQuery("discovery_source", "MS SMS");
grCI.addQuery("serial_number", serialNum[i]);
grCI.query();
while (grCI.next()) {
var grAlm = new GlideRecord("alm_hardware");
grAlm.addQuery("serial_number", serialNum[i]);
grAlm.query();
while (grAlm.next()) {
grAlm.ci = grCI.sys_id.toString();
grAlm.setWorkflow(false);
grAlm.update();
}
}
}
var serialNum = ["1N44FW2", "1PR8YW2", "1QDKGP2"];
for (var i = 0; i < serialNum.length; i++) {
var grCI = new GlideRecord("cmdb_ci_hardware");
grCI.addEncodedQuery('sys_class_name=cmdb_ci_computer');
grCI.addQuery("discovery_source", "NULL");
grCI.addQuery("serial_number",serialNum[i]);
grCI.query();
while (grCI.next()) {
var grCI1 = new GlideRecord("cmdb_ci_hardware");
grCI1.addEncodedQuery('sys_class_name=cmdb_ci_computer');
grCI1.addQuery("discovery_source", "MS SMS");
grCI1.addQuery("serial_number", serialNum[i]);
grCI1.query();
while (grCI1.next()) {
grCI1.asset = grCI.asset;
grCI1.update();
}
}
}
// Manually Create record in windows Server or any other class using script
var payload = {
"items": [
{
"className": "u_cmdb_ci_mongoose_web_server",
"lookup": [],
"values": {
"name": "Mongoose@owa-sd-01",
"version": “5.5”,
"running_process_command": "c:\\clouddimensions\\mongoose.exe",
"sys_class_name": "u_cmdb_ci_mongoose_web_server"
}
},
{
"className": "cmdb_ci_win_server",
"lookup": [],
"values": {
"name": "OWA-SD-01"
}
}
],
"relations": [
{
"type": "Runs on::Runs",
"parent": 0,
"child": 1
}
]
};
var jsonUtil = new JSON();
var input = jsonUtil.encode(payload);
var output = SNC.IdentificationEngineScriptableApi.createOrUpdateCI(‘ServiceNow’, input);
gs.print(output);
//Azure Fundamental : -
Remove Middle name from a name in Excel Sheet .
Using formula may be a very easy way for most of Excel users.
Select a blank cell next to the name list, and type this formula =TRIM(LEFT(A1,FIND(" ",LOWER(A1),1))) & " " & TRIM(MID(A1,FIND(" ",LOWER(A1),FIND(" ",LOWER(A1),1)+1)+1,LEN(A1)-FIND(" ",LOWER(A1),1)+1)) into it, then press Enter button on the keyboard and drag the Auto Fill handle to fill the range needed to apply the formula. Now you can see all the name of the list are shown in the new column without middle initials.
// Get all the incidents updated 3 days before
var dupRecords = [];
var count = '';
var gr = new GlideRecord('incident');
gr.addQuery('sys_updated_onRELATIVEGE@dayofweek@ago@3');
gr.query();
while(gr.next()){
dupRecords.push(gr.number);
}
gs.print(dupRecords);
var dupRecords = [];
var count = '';
var gr = new GlideRecord('incident');
gr.addQuery('sys_updated_onRELATIVEGE@dayofweek@ago@3');
gr.query();
while(gr.next()){
dupRecords.push(gr.number);
}
gs.print(dupRecords);
Client Script Date/Time Functions
- getNowDateTimeDiff
This ajax function will allow you to calculate the date/time difference between a field on the form and the now date/time. You can specify a return type - "dttype" to get the result in seconds, minutes, hours, or days. See the comment below for the parameter values.
var cdt = g_form.getValue('due_date'); //First Date/Time field
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); }
- getDateTimeDiff
This ajax function will allow you to send in two different glide date/time fields and return a calculation of their date/time difference in seconds, minutes, hours, or days.
var cdt = g_form.getValue('due_date'); //First Date/Time field
var sdt = g_form.getValue('expected_start'); //Second Date/Time field
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_sdt', sdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);- getDateTimeBeforeNow
This ajax function will take a glide date/time field and return the amount of time till the now date/time. A positive number will represent prior to now, and negative will be how much time after now. This is pretty much a duplicate of the first one "getNowDateTimeDiff" but it gives you the opposite in positive, negative numbers. Positive = before, negative = after.
var cdt = g_form.getValue('due_date'); //first Date/Time field
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNow');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}- getDateTimeBeforeNowBool
This ajax function will return a true or false if the date/time field is before the now date/time. This made it simpler, rather than having to do more processing on the client side, just evaluate true/false. Makes it simple.
var cdt = g_form.getValue('due_date'); //first Date/Time field
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNowBool');
ajax.addParam('sysparm_fdt', cdt);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- getNowDateTime
This function returns the date and time of right now.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTime');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
- getNowDate
This function returns the date of right now.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDate');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);- getNowTime
This function returns the time of right now.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowTime');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);- addDateTimeAmount
With this ajax function you can add more time to a glide date/time field. You can add seconds, minutes, hours, days, weeks, months, and years. If you want to take time away, use a negative number in the addtime variable.
Limitation:
One limitation that I have found so far is in the return date/time format. The added-to-time new date/time is returned in the standard internal date/time format. I am trying to figure out how to return it based on the user defined date/time format. Still a work in progress.
var cdt = g_form.getValue('due_date'); //Choose the field to add time from
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be second, minute, hour, day, week, month, year.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateTimeAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//You could then take the new Date/Time answer and set the value of another field.
// g_form.setValue('expected_start', answer);
alert(answer);
}- addDateAmount
This is a function to add time to a Glide Date field. You can add days, weeks, months, or years.
var cdt = g_form.getValue('some_date'); //Choose the field to add time from
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be day, week, month, year.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); }
- addTimeAmount
This is a function to add time to a Glide Time field. You can add seconds, minutes, hours.
var cdt = g_form.getValue('some_time_field'); //Choose the field to add time from
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be second, minute, hour.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addTimeAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
This ajax function will allow you to calculate the date/time difference between a field on the form and the now date/time. You can specify a return type - "dttype" to get the result in seconds, minutes, hours, or days. See the comment below for the parameter values.
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
This ajax function will allow you to send in two different glide date/time fields and return a calculation of their date/time difference in seconds, minutes, hours, or days.
var sdt = g_form.getValue('expected_start'); //Second Date/Time field
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_sdt', sdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
This ajax function will take a glide date/time field and return the amount of time till the now date/time. A positive number will represent prior to now, and negative will be how much time after now. This is pretty much a duplicate of the first one "getNowDateTimeDiff" but it gives you the opposite in positive, negative numbers. Positive = before, negative = after.
var dttype = 'minute'; //this can be day, hour, minute, second. By default it will return seconds.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNow');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
This ajax function will return a true or false if the date/time field is before the now date/time. This made it simpler, rather than having to do more processing on the client side, just evaluate true/false. Makes it simple.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeBeforeNowBool');
ajax.addParam('sysparm_fdt', cdt);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
This function returns the date and time of right now.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTime');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
This function returns the date of right now.
ajax.addParam('sysparm_name','getNowDate');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
This function returns the time of right now.
ajax.addParam('sysparm_name','getNowTime');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
With this ajax function you can add more time to a glide date/time field. You can add seconds, minutes, hours, days, weeks, months, and years. If you want to take time away, use a negative number in the addtime variable.
Limitation:
One limitation that I have found so far is in the return date/time format. The added-to-time new date/time is returned in the standard internal date/time format. I am trying to figure out how to return it based on the user defined date/time format. Still a work in progress.
var cdt = g_form.getValue('due_date'); //Choose the field to add time from
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be second, minute, hour, day, week, month, year.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateTimeAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//You could then take the new Date/Time answer and set the value of another field.
// g_form.setValue('expected_start', answer);
alert(answer);
This is a function to add time to a Glide Date field. You can add days, weeks, months, or years.
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be day, week, month, year.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
This is a function to add time to a Glide Time field. You can add seconds, minutes, hours.
var cdt = g_form.getValue('some_time_field'); //Choose the field to add time from
var addtime = 3; //The amount of time to add
var addtype = 'day'; //The time type. Can be second, minute, hour.
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addTimeAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
I got my expected result in the Final Professional VMware vSphere 7.x Exam. I had an outstanding experience with VMware 2V0-21.20 Dumps and I recommend all to go for the VMware Certified Professional Certification Exam preparation with this VMware 2V0-21.20 PDF Dumps. I also used their VMware 2V0-21.20 Practice Test Software and VMware 2V0-21.20 Web-Based Test too for my preparation, which was very helpful in knowing and improving my mistakes.
ReplyDelete