function OnChangeofClientNameOrEngagementNumber(executionContext) { var formContext = executionContext.getFormContext(); var clientName = formContext.getAttribute("coesched_clientname").getValue(); var engagementNumber = formContext.getAttribute("coesched_cyengagementnumber").getValue(); if(clientName == null) { clientName = ""; } if(engagementNumber == null) { engagementNumber = ""; } var engagementName = clientName + ' - ' + engagementNumber; formContext.getAttribute("coesched_name").setValue(engagementName); } function AddPreSearchToRegion(executionContext) { formContext = executionContext.getFormContext(); //Create form if(formContext.ui.getFormType() == 1) { formContext.getControl("coesched_region").addPreSearch( function () { ApplyFilterBasedOnArea(executionContext); } ); } else{ formContext.getControl("coesched_area").setDisabled(true); formContext.getControl("coesched_region").setDisabled(true); } } function ApplyFilterBasedOnArea(executionContext) { formContext = executionContext.getFormContext(); var area = formContext.getAttribute("coesched_area").getValue(); if (area != null && area != undefined) { var areaId = area[0].id; var filter = "<filter type='and'>" + "<condition attribute='coesched_areaid' operator='eq' value='" + areaId + "' />" + "</filter>"; formContext.getControl("coesched_region").addCustomFilter(filter); } } function OnLoadSetAreaAndRegionBasedOnLoggedInUser(executionContext) { formContext = executionContext.getFormContext(); var loggedInUserId = formContext._globalContext.getUserId().replace("{","").replace("}",""); var _businessunitid_value_formatted; var _parentbusinessunitid_value_formatted; var _parentParentbusinessunitid_value_formatted; if (loggedInUserId !== null && formContext.ui.getFormType() == 1) { Xrm.WebApi.online.retrieveMultipleRecords("systemuser", "?$select=_businessunitid_value&$filter=systemuserid eq '"+ loggedInUserId +"'").then( function success(userBUS) { for (var i = 0; i < userBUS.entities.length; i++) { var _businessunitid_value = userBUS.entities[i]["_businessunitid_value"]; _businessunitid_value_formatted = userBUS.entities[i]["[email protected]"]; Xrm.WebApi.online.retrieveRecord("businessunit", _businessunitid_value, "?$select=_parentbusinessunitid_value").then( function success(userParentBU) { var _parentbusinessunitid_value = userParentBU["_parentbusinessunitid_value"]; _parentbusinessunitid_value_formatted = userParentBU["_parentbusinessunitid_value@OData.Community.Display.V1.FormattedValue"]; if(_parentbusinessunitid_value !== undefined && _parentbusinessunitid_value !== null) { Xrm.WebApi.online.retrieveRecord("businessunit", _parentbusinessunitid_value, "?$select=_parentbusinessunitid_value").then( function success(userParentBUParent) { var _parentParentbusinessunitid_value = userParentBUParent["_parentbusinessunitid_value"]; _parentParentbusinessunitid_value_formatted = userParentBUParent["_parentbusinessunitid_value@OData.Community.Display.V1.FormattedValue"]; if( _parentParentbusinessunitid_value !== null && _parentParentbusinessunitid_value !== undefined) { //Set area and region Xrm.WebApi.online.retrieveMultipleRecords("coesched_area", "?$select=coesched_areaid,coesched_name&$filter=coesched_name eq '"+ _parentbusinessunitid_value_formatted +"'").then( function success(areas) { for (var i = 0; i < areas.entities.length; i++) { var coesched_areaid = areas.entities[i]["coesched_areaid"]; var coesched_areaname = areas.entities[i]["coesched_name"]; var areaLookupValue = new Array(); areaLookupValue[0] = new Object(); areaLookupValue[0].entityType = "coesched_area"; areaLookupValue[0].id = coesched_areaid; areaLookupValue[0].name = coesched_areaname; formContext.getAttribute("coesched_area").setValue(areaLookupValue); formContext.getControl("coesched_area").setDisabled(true); Xrm.WebApi.online.retrieveMultipleRecords("coesched_region", "?$select=coesched_name,coesched_regionid&$filter=coesched_name eq '"+ _businessunitid_value_formatted +"'").then( function success(regions) { for (var i = 0; i < regions.entities.length; i++) { var coesched_regionname = regions.entities[i]["coesched_name"]; var coesched_regionid = regions.entities[i]["coesched_regionid"]; var regionLookupValue = new Array(); regionLookupValue[0] = new Object(); regionLookupValue[0].entityType = "coesched_region"; regionLookupValue[0].id = coesched_regionid; regionLookupValue[0].name = coesched_regionname; formContext.getAttribute("coesched_region").setValue(regionLookupValue); formContext.getControl("coesched_region").setDisabled(true); } }, function(error) { Xrm.Utility.alertDialog(error.message); } ); } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } else{ //Set only area Xrm.WebApi.online.retrieveMultipleRecords("coesched_area", "?$select=coesched_areaid,coesched_name&$filter=coesched_name eq '"+ _businessunitid_value_formatted +"'").then( function success(areas) { for (var i = 0; i < areas.entities.length; i++) { var coesched_areaid = areas.entities[i]["coesched_areaid"]; var coesched_areaname = areas.entities[i]["coesched_name"]; var areaLookupValue = new Array(); areaLookupValue[0] = new Object(); areaLookupValue[0].entityType = "coesched_area"; areaLookupValue[0].id = coesched_areaid; areaLookupValue[0].name = coesched_areaname; formContext.getAttribute("coesched_area").setValue(areaLookupValue); formContext.getControl("coesched_area").setDisabled(true); } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } else{ formContext.getControl("coesched_area").setDisabled(true); formContext.getControl("coesched_region").setDisabled(true); } } function ShowAndMarkFieldsAsMandatoryBasedOnPBTSubgrid(executionContext) { debugger; //Not a create form formContext = executionContext.getFormContext(); if(formContext.ui.getFormType() !== 1) { formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosingdebtequity","coesched_explanationfornotchoosingdebtequity"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosinginventory","coesched_explanationfornotchoosinginventory"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosinginvestments","coesched_explanationfornotchoosinginvestments"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosingordertocash","coesched_explanationfornotchoosingordertocash"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosingp2p","coesched_explanationfornotchoosingp2p"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").addOnChange( function () { OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, "coesched_selectareasonfornotchoosingpayroll","coesched_explanationfornotchoosingpayroll"); } ); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").addOnChange( function () { OnChangeOfDecimalFields(executionContext, "coesched_selectareasonfornotchoosingppe","coesched_explanationfornotchoosingppe"); } ); var existingPBTList = {}; var engagementTicketId = formContext.data.entity.getId(); Xrm.WebApi.online.retrieveMultipleRecords("msdyn_project", "?$select=_coesched_engagementticketid_value,coesched_pbt&$filter=_coesched_engagementticketid_value eq '"+ engagementTicketId +"' and coesched_projecttype eq true").then( function success(pbtProjects) { if(pbtProjects.entities.length !== 0 && pbtProjects.entities.length !== 7){ for (var i = 0; i < pbtProjects.entities.length; i++) { var _coesched_engagementticketid_value = pbtProjects.entities[i]["_coesched_engagementticketid_value"]; var _coesched_engagementticketid_value_formatted = pbtProjects.entities[i]["_coesched_engagementticketid_value@OData.Community.Display.V1.FormattedValue"]; var _coesched_engagementticketid_value_lookuplogicalname = pbtProjects.entities[i]["_coesched_engagementticketid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; var coesched_pbt = pbtProjects.entities[i]["coesched_pbt"]; var coesched_pbt_formatted = pbtProjects.entities[i]["[email protected]"]; existingPBTList.push(coesched_pbt); } ShowFieldsBasedValuesInExistingPBTList(executionContext,existingPBTList); } else{ //Show Not Chosen PBT Section marking all fields not mandatory and clearing all the data formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingppe").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setValue(); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setValue(); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingppe").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setValue(); // Hide whole section } }, function(error) { Xrm.Utility.alertDialog(error.message); }); } else{ //Hide Section } } function ShowFieldsBasedValuesInExistingPBTList(executionContext,existingPBTList){ //Order To Cash if(existingPBTList.includes(1)) { formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosingordertocash").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosingordertocash").setVisible(true); } //Inventory if(existingPBTList.includes(2)) { formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setValue(); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosinginventory").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosinginventory").setVisible(true); } //Property Plant And Equipment if(existingPBTList.includes(3)) { formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosingppe").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingppe").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingppe").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosingppe").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosingppe").setVisible(true); } //Payroll if(existingPBTList.includes(4)) { formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setVisible(false); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosingpayroll").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosingpayroll").setVisible(true); } //Investments if(existingPBTList.includes(5)) { formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setValue(); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosinginvestments").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosinginvestments").setVisible(true); } //Debt And Equity if(existingPBTList.includes(6)) { formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosingdebtequity").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosingdebtequity").setVisible(true); } //Procure To Pay if(existingPBTList.includes(7)) { formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setRequiredLevel("none"); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setValue(); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setVisible(false); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setRequiredLevel("none"); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setValue(); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setVisible(false); } else{ formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setRequiredLevel("required"); formContext.getAttribute("coesched_selectareasonfornotchoosingp2p").setVisible(true); formContext.getAttribute("coesched_explanationfornotchoosingp2p").setVisible(true); } } function OnChangeOfSelectAReasonForNotChoosingThisPBT(executionContext, selectAReasonField, explanationField){ formContext = executionContext.getFormContext(); var selectaReasonForNotChoosingThisPBTValue = formContext.getAttribute(selectAReasonField).getValue(); //Others if(selectaReasonForNotChoosingThisPBTValue === 7) { formContext.getAttribute(explanationField).setRequiredLevel("required"); } else{ formContext.getAttribute(explanationField).setRequiredLevel("none"); formContext.getAttribute(explanationField).setValue(); } } //"EngagementTicketLines"
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");