jQuery Basic Syntax
In Microsoft D365, jQuery is mostly used in different CRM portal for development purpose.
Providing basic syntax required to Get/Set field value in jQuery :
1. TextField :
var firstname = $("#firstname").val(); //get
var lastname = $("#lastname").val("Tendulkar"); //set
2. OptionSet :
var type = $("#typecode").val(); //get
var type = $("#typecode").val(16350000); //set (enter code of optionset field)
3. Lookup :
//Get Lookup Value
var lookupGUID = $(“#new_accountid”).val();
var lookupValue = $(“#new_ accountid_name”).val();
var entityName= $(“#new_accountid_entityname”).val();
//set Lookup Value
$(“#new_accountid”).val(lookupId);
$(“#new_accountid_name”).val(lookupName);
$(“# new_accountid_entityname”).val(EntitySchemaName);
4. CheckBox : //Get Checkbox value
var isChecked = $(“#{field_name}”).is(“:checked”);
if (isChecked == true) {
alert(“Checked!”);
}
else if (isChecked == false) {
alert(“Unchecked!”);
}
//set CheckBox Value
$(‘#{fieldname}’).prop(‘checked’, true);
5. Radio Button : Radio button has 2 controls (eg. Yes and No). Hence, we need to get/set both the controls value as per business requirement.
//Get two controls of radio button
var isOption1Checked = $(“#{field_name_0}”).is(“:checked”); //Returns true/false
var isOption2Checked = $(“#{field_name_1}”).is(“:checked”); //Returns true/false
//Set two controls of radio button
// To setRadio 1 to 'true'
$(‘#{fieldname_0}’).prop(‘checked’, true);
// To set Radio 2 to ‘true’
$(‘#{fieldname_1}’).prop(‘checked’, true);
6. On Change of field (text/lookup/optionset) :
$("#new_name").change(function() {
//call your function or apply your logic here!
});
Comments
Post a Comment