Java script Task1: In case entity, based on incident type selection, filter the case category using the category-incident master entity?
Create incident type entity
2) Create case category entity
3) Create category incident master entity
4) In case entity provide the lookup of incident type, case category
5) On change of incident type – form type: 1
Read the selected incident type
Read the case category
If incident type is null then disable the case category
If Incident type is not null and then enable the case category
Prepare fetch Xml for the advanced find view to get the case based on incident type
Create custom filter view to show retrieved case categories –
6) On change of case category
If incident type is null then read the selected case category
Prepare fetch Xml for the advanced find view to get the case based on Case categories
Create custom filter view to show retrieved incident type
BY using below condition download Fetch XML
Creation of master Entity:
· Here am creating master entity/Link entity named as Category-Incident
· In this entity whenever am selecting Incident type and Case category then Name field should be updated based on Incident type and Case category field value.
Code for above scenario:
function case_incident(excecutionContext) {
var formContext = excecutionContext.getFormContext();
var incidenttype = formContext.getAttribute("effi_incidenttype").getValue();
var casecategory = formContext.getAttribute("effi_casecategory").getValue();
if (incidenttype != null && casecategory != null) {
var incidentName = incidenttype[0].name;
var casecategoryName = casecategory[0].name;
var name = incidentName + " - " + casecategoryName;
formContext.getAttribute("effi_name").setValue(name);
}
}
Add above code in web resource and add this web resource in category-incident form properties
If you not entering any value in Incident type up to entering any input, Case category should be in read only format
Code for above scenario:
//onload readonly
function casecategoryDisable(executionContext) {
var formContext = executionContext.getFormContext();
var incidenttype = formContext.getAttribute("effi_incidenttype").getValue();
if (incidenttype == null && incidenttype == undefined) {
formContext.getControl("effi_casecategory").setDisabled(true);
}
else {
formContext.getControl("effi_casecategory").setDisabled(false);
}
}
Add above code in to web resource and choose form onload event
//field change read only
function casecategoryDisablefieldchange(executionContext) {
var formContext = executionContext.getFormContext();
var incidenttype = formContext.getAttribute("effi_incidenttype").getValue();
if (incidenttype != null && incidenttype != undefined) {
formContext.getControl("effi_casecategory").setDisabled(false);
}
else {
formContext.getControl("effi_casecategory").setDisabled(true);
}
}
Add above code in web resource
Choose on-change event of Incident type field
Whenever you ‘re opening the form at the time case category field in read only format but when enter any input into Incident type field then Case category will convert into editable format.
In case entity for filtering the case category based on incident type we can use fetch xml
Below is the condition for filtering the case category to download the fetch XML
Open any browser and search Fetch xml formatter
Copy and paste the downloaded fetch xml
Select middle page of the code and copy
This fetch xml code we can use in java script code
Java script code:
function filterCaseCategory(executionContext) {
var formContext = executionContext.getFormContext();
var incidentType = formContext.getAttribute("new_incidenttype").getValue();
if (incidentType != null && incidentType != undefined) {
var incidentType_id = incidentType[0].id;
var incidentType_name = incidentType[0].name;
var entityName = "effi_casecategory";
var viewDisplayName = "FilteredCaseCtegory";
var viewId = "{00000000-0000-0000-0000-000000000008}";
var fetchQuery = "<fetch
version='1.0' output-format='xml-platform' mapping='logical'
distinct='false'>" +
"<entity
name='effi_casecategory'>" +
"<attribute
name='effi_casecategoryid'/>" +
"<attribute
name='effi_name'/>" +
"<attribute
name='createdon'/>" +
"<order
attribute='effi_name' descending='false'/>" +
"<link-entity
name='effi_categoryincident' from='effi_casecategory' to='effi_casecategoryid'
link-type='inner' alias='ab'>" +
"<attribute
name='effi_incidenttype'/>" +
"<filter
type='and'>" +
"<condition
attribute='effi_incidenttype' operator='eq' uiname='" + incidentType_name + "'
uitype='effi_incidenttype' value= '" +
incidentType_id + "'/>" +
"</filter>" +
"</link-entity>" +
"</entity>" +
"</fetch>";
var layout =
"<grid
name='resultset' icon='1' preview='1' select='1' jump='effi_name'
object='5'>" +
"<row
name='result' id='effi_casecategoryid' >"
+
"<cell
name='effi_name' width='300'/>" +
"<cell
name='ab.effi_incidenttype' width='300'/>" +
//"<cell
name='createdon' width='300'/>" +
"</row>" +
"</grid>";
formContext.getControl("new_casecategory").addCustomView(viewId,
entityName, viewDisplayName, fetchQuery, layout, true);
}
else {
return false;
}
}
Add above code in Web Resource
Go to case entity form properties and add web Resource
In Event Handler section
Control: field name (Incident type)
Event: OnChange
Click on Add button (Event Handler section)
Click on Ok and Publish
Output:
Whenever you’re selected Incident type as Database then database related values only shown in case category field
Comments
Post a Comment