- Jscript to hide unpopulated fields
- Posted by Mark Braithwaite on April 8th, 2008
Hi
We have created two custom entities named suppliers and business partners.
We would prefer not to create account records and use the relationship type
field so we created these custom entities.
We now have on the Contact form three seperate fields that a contact could
be related to. These fields are parent customer, parent supplier and parent
business partner. A Contact should only be associated with one parent record.
We would like to write Jscript which hides the remaining fields if one of
the fields is populated. If a user associates a Contact with a parent
customer then the parent business partner and parent supplier fields are
hidden.
If I use the On Save event, the question is, how do I hide the remaining
fields if a certain value is selected in one of the fields? I only want to
hide the fields that are not populated.
I suppose I could use a script which if all fields are null then do nothing
however if one of the fields are populated then hide the fields that are
null. How would you translate this into Jscript?
I created a custom field named 'Contact Type' and tested the following script:
var type = crmForm.all.new_contacttype.SelectedText;
switch (type)
{
case "Business Partner
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'visible';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'relative';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'visible';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'relative';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'visible';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'relative';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute';
case "Supplier"
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'visible';
crmForm.all.new_parentsupplierid.style.position = 'relative';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'visible';
crmForm.all.new_parentsupplierid_c.style.position = 'relative';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'visible;
crmForm.all.new_parentsupplierid_d.style.position = 'relative';
break;
case "Customer"
crmForm.all.parentcustomerid.style.visibility = 'visible';
crmForm.all.parentcustomerid.style.position = 'relative';
crmForm.all.parentcustomerid_c.style.visibility = 'visible';
crmForm.all.parentcustomerid_c.style.position = 'relative';
crmForm.all.parentcustomerid_d.style.visibility = 'visible';
crmForm.all.parentcustomerid_d.style.position = 'relative';
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute';
break;
This script was unsuccessful and I would ideally prefer not to create the
custom field named 'Contact Type'.
Thanks very much
- Posted by Niths on April 9th, 2008
Hi Mark,
How about using If..then constructs to check if a value is present in one of
the three lookup fields?
To get the value in a lookup, you would need to use:
crmForm.all.lookupfield.nextSibling.InnerText
Do write in if you have problems using this script.
HTH,
Niths
"Mark Braithwaite" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
Thanks for your reply. Okay so the begining of part of my script would be
if
crmForm.all.new_parentsupplierid.nextSibling.Inner Text II
crmForm.all.new_parentbusinesspartnerid.nextSiblin g.InnerText II
crmForm.all.parentcustomerid.nextSibling.InnerText != null
then ........
My question is how do I hide only the fields that are null if one of them is
populated. To be honest I may be lacking the skills to write the Jscript
required. Appreciate your assistance.
Thanks again
Mark
"Niths" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
Thanks for your reply. Okay so the begining of part of my script would be
if
crmForm.all.new_parentsupplierid.nextSibling.Inner Text II
crmForm.all.new_parentbusinesspartnerid.nextSiblin g.InnerText II
crmForm.all.parentcustomerid.nextSibling.InnerText != null
then ........
My question is how do I hide only the fields that are null if one of them is
populated. To be honest I may be lacking the skills to write the Jscript
required. Appreciate your assistance.
Thanks again
Mark
"Niths" wrote:
- Posted by Niths on April 9th, 2008
Hi Mark,
Try this:
var lkupval1 = crmForm.all.new_parentsupplierid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.new_parentbusinesspartnerid_c.style.di splay="none";
crmForm.all.new_parentbusinesspartnerid_d.style.di splay="none";
crmForm.all.new_parentcustomerid_c.style.display=" none";
crmForm.all.new_parentcustomerid_d.style.display=" none";
}
and likewise for the parentbusinesspartnerid and parentcustomerid fields.
HTH,
Niths
"Mark Braithwaite" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
Thanks again for your reply. I tested the following script:
var lkupval1 = crmForm.all.new_parentsupplierid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.parentcustomerid_c.style.display = 'none';
crmForm.all.parentcustomerid_d.style.display = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
}
var lkupval1 = crmForm.all.new_parentbusinesspartnerid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.parentcustomerid_c.style.display = 'none';
crmForm.all.parentcustomerid_d.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
}
var lkupval1 = crmForm.all.parentcustomerid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
}
I received an error message stating that '0' or is null or not an object.
Any ideas why this occurring?
Thanks so much for your help.
Regards
Mark
"Niths" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
Thanks again for your reply. I tested the following script:
var lkupval1 = crmForm.all.new_parentsupplierid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.parentcustomerid_c.style.display = 'none';
crmForm.all.parentcustomerid_d.style.display = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
}
var lkupval1 = crmForm.all.new_parentbusinesspartnerid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.parentcustomerid_c.style.display = 'none';
crmForm.all.parentcustomerid_d.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
}
var lkupval1 = crmForm.all.parentcustomerid.DataValue;
if (lkupval1[0] != null)
{
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentsupplierid.style.display = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
crmForm.all.new_parentbusinesspartnerid.style.disp lay = 'none';
}
I received an error message stating that '0' or is null or not an object.
Any ideas why this occurring?
Thanks so much for your help.
Regards
Mark
"Niths" wrote:
- Posted by Niths on April 9th, 2008
Hi Mark,
Where did you put this script? Did you put in the onChange event of the
lookups?
HTH,
Niths
"Mark Braithwaite" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
I am using the OnSave event and my final script looks like this:
var lkupval1 = crmForm.all.new_parentsupplierid.DataValue;
if (lkupval1 != null)
{
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
}
crmForm.all.new_parentsupplierid.ForceSubmit = true;
var lkupval2 = crmForm.all.new_parentbusinesspartnerid.DataValue;
if (lkupval2 != null)
{
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute';
}
crmForm.all.new_parentbusinesspartnerid.ForceSubmi t = true;
var lkupval3 = crmForm.all.parentcustomerid.DataValue;
if (lkupval3 != null)
{
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute'
}
crmForm.all.parentcustomerid.ForceSubmit = true;
Everything works perfectly except for one small glitch. If I 'Save', the
fields that are null disappear however if I 'Save and Close' and reopen the
form the fields that are null reappear. I am trying to use the ForceSubmit =
true however this does not seem to be working.
Would you assist me with this last bit?
Thanks again for all your help.
Mark
"Niths" wrote:
- Posted by Mark Braithwaite on April 9th, 2008
Hi Niths
I am using the OnSave event and my final script looks like this:
var lkupval1 = crmForm.all.new_parentsupplierid.DataValue;
if (lkupval1 != null)
{
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
}
crmForm.all.new_parentsupplierid.ForceSubmit = true;
var lkupval2 = crmForm.all.new_parentbusinesspartnerid.DataValue;
if (lkupval2 != null)
{
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute';
}
crmForm.all.new_parentbusinesspartnerid.ForceSubmi t = true;
var lkupval3 = crmForm.all.parentcustomerid.DataValue;
if (lkupval3 != null)
{
crmForm.all.new_parentbusinesspartnerid.style.visi bility = 'hidden';
crmForm.all.new_parentbusinesspartnerid.style.posi tion = 'absolute';
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_c.style.po sition = 'absolute';
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = 'hidden';
crmForm.all.new_parentbusinesspartnerid_d.style.po sition = 'absolute';
crmForm.all.new_parentsupplierid.style.visibility = 'hidden';
crmForm.all.new_parentsupplierid.style.position = 'absolute';
crmForm.all.new_parentsupplierid_c.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_c.style.position = 'absolute';
crmForm.all.new_parentsupplierid_d.style.visibilit y = 'hidden';
crmForm.all.new_parentsupplierid_d.style.position = 'absolute'
}
crmForm.all.parentcustomerid.ForceSubmit = true;
Everything works perfectly except for one small glitch. If I 'Save', the
fields that are null disappear however if I 'Save and Close' and reopen the
form the fields that are null reappear. I am trying to use the ForceSubmit =
true however this does not seem to be working.
Would you assist me with this last bit?
Thanks again for all your help.
Mark
"Niths" wrote:
- Posted by Niths on April 9th, 2008
Great, you got it working!
Well to ensure that the fields stay hidden on form load, put the same script
you've used in the OnSave event into form onLoad.
HTH,
Niths
"Mark Braithwaite" wrote:
- Posted by Huib (crm.atechnisch.nl) on April 16th, 2008
Mark,
if you are using client side code to modify the appearance of the screen,
you have to use the onLoad or the onChange events. If you are using the
onSave event, your changes will be lost when the screen is reloaded.
I used the following code (in the onLoad) in the past:
http://crm.atechnisch.nl/2008/01/25/...-empty-fields/
Good luck.
regards
Huib