Hi,
I'm trying to achieve the following:
I've got a field on the account form called "scp_relationshiptype_mc", which is a multi-select option set with several values.
Depending on which value is selected, another field will be shown.
Eg.: If someone picks options "A", "B", and "C" in the MC option set field, three otherwise hidden fields "scp_A", scp_B" and "scp_C" will become visible. If they pick "A" and "B", only "scp_A" en "scp_B" ought to be shown.
It is disappointing that I can use MC option sets, but I can't do anything with them in a business rule or a workflow, so I've resorted to using JavaScript. I'm not a developer, so pardon any rookie mistakes.
I've gotten this far:
function onLoad() {
ShowHideRT();
}
function ShowHideRT() {
if ("scp_relationshiptype_mc" !== null)
{
//EV
if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200000))
{
Xrm.Page.getControl("scp_rt_specifyev").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//TechPartner
else if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200001))
{
Xrm.Page.getControl("scp_rt_specifytechpartner").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//GridOp
else if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200002))
{
Xrm.Page.getControl("scp_rt_specifygridoperator").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//ServComp
else if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200003))
{
Xrm.Page.getControl("scp_rt_specifyservicecompany").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//BuildConstr
else if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200004))
{
Xrm.Page.getControl("scp_rt_specifybuildingconstruction").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//NonTrad
else if (Xrm.Page.getAttribute("scp_relationshiptype_mc").getValue().includes(798200005))
{
Xrm.Page.getControl("scp_specifynontraditional").setVisible(true);
Xrm.Page.getControl("scp_relationshiptypecomment").setVisible(true);
}
//Other...
}
}
This JS is called in the onLoad of the Account page and the onChange of the "scp_relationshiptype_mc" field.
When I try to open the account page, I get the error:
TypeError: Cannot read property 'includes' of null at ShowHideR
I had hoped that .include method would help me retrieve the necessary values to check on.
Help is much appreciated!