I am having an issue with the below script. When I put information in the null fields below and having nhs_accumulatorsource not filled in, then click save, it wipes the data out and it shouldn't. It should only wipe the data out when nhs_accumulatorsource contains data
function AccumulatorIDOnChange()
{
var AccumulatorID = Xrm.Page.getAttribute("nhs_accumulatorsource").getValue();
if (AccumulatorID != null || AccumulatorID != 'undefined' || AccumulatorID !='')
{
Xrm.Page.getAttribute("new_fileformat").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfilelayoutcomment").setValue(null);
Xrm.Page.getAttribute("nhs_programmingtype").setValue(null);
Xrm.Page.getAttribute("nhs_ftpprovider").setValue(null);
Xrm.Page.getAttribute("new_productionftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_productionfilename").setValue(null);
Xrm.Page.getAttribute("new_monday").setValue(null);
Xrm.Page.getAttribute("new_tuesday").setValue(null);
Xrm.Page.getAttribute("new_wednesday").setValue(null);
Xrm.Page.getAttribute("new_thursday").setValue(null);
Xrm.Page.getAttribute("new_friday").setValue(null);
Xrm.Page.getAttribute("new_saturday").setValue(null);
Xrm.Page.getAttribute("new_sunday").setValue(null);
Xrm.Page.getAttribute("new_approximateloadtime").setValue(null);
Xrm.Page.getAttribute("nhs_holidayschedule").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfrequencycomments").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorresultserrorfile").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilename").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilecomments").setValue(null);
}
}
function AccumulatorIDOnLoad()
{
AccumulatorIDOnChange();
}
*This post is locked for comments
Thank you.
Add the following function to your code:
function getLookupName(fieldName) {
var field = Xrm.Page.getAttribute(fieldName);
if (field != null) {
var fieldId = field.getValue();
if (fieldId != null)
return fieldId[0].name.toString();
else
return '';
}
}
In your AccumulatorIDOnChange replace the following code:
var AccumulatorID = Xrm.Page.getAttribute("nhs_accumulatorsource").getValue();
//var lookupName = null;
if(lookup != null)
var lookupName = lookup[0].name;
if (lookupName != null && lookupName != 'undefined' && lookupName !='')
with
var AccumulatorID = getLookupName("nhs_accumulatorsource");
if (AccumulatorID != '')
That should be it.
Getting error that lookup is undefined
function AccumulatorIDOnChange()
{
var AccumulatorID = Xrm.Page.getAttribute("nhs_accumulatorsource").getValue();
var lookupName = null;
if(lookup != null)
var lookupName = lookup[0].name;
if (lookupName != null || lookupName != 'undefined' || lookupName !='')
{
Xrm.Page.getAttribute("new_fileformat").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfilelayoutcomment").setValue(null);
Xrm.Page.getAttribute("nhs_programmingtype").setValue(null);
Xrm.Page.getAttribute("nhs_ftpprovider").setValue(null);
Xrm.Page.getAttribute("new_productionftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_productionfilename").setValue(null);
Xrm.Page.getAttribute("new_monday").setValue(null);
Xrm.Page.getAttribute("new_tuesday").setValue(null);
Xrm.Page.getAttribute("new_wednesday").setValue(null);
Xrm.Page.getAttribute("new_thursday").setValue(null);
Xrm.Page.getAttribute("new_friday").setValue(null);
Xrm.Page.getAttribute("new_saturday").setValue(null);
Xrm.Page.getAttribute("new_sunday").setValue(null);
Xrm.Page.getAttribute("new_approximateloadtime").setValue(null);
Xrm.Page.getAttribute("nhs_holidayschedule").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfrequencycomments").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorresultserrorfile").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilename").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilecomments").setValue(null);
}
}
Sorry.. later to the party.. Aric has covered it..
Would it be something like this?
function AccumulatorIDOnChange()
{
var AccumulatorID = Xrm.Page.getAttribute("nhs_accumulatorsource").getValue();
//var lookupName = null;
if(lookup != null)
var lookupName = lookup[0].name;
if (lookupName != null && lookupName != 'undefined' && lookupName !='')
{
Xrm.Page.getAttribute("new_fileformat").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfilelayoutcomment").setValue(null);
Xrm.Page.getAttribute("nhs_programmingtype").setValue(null);
Xrm.Page.getAttribute("nhs_ftpprovider").setValue(null);
Xrm.Page.getAttribute("new_productionftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_productionfilename").setValue(null);
Xrm.Page.getAttribute("new_monday").setValue(null);
Xrm.Page.getAttribute("new_tuesday").setValue(null);
Xrm.Page.getAttribute("new_wednesday").setValue(null);
Xrm.Page.getAttribute("new_thursday").setValue(null);
Xrm.Page.getAttribute("new_friday").setValue(null);
Xrm.Page.getAttribute("new_saturday").setValue(null);
Xrm.Page.getAttribute("new_sunday").setValue(null);
Xrm.Page.getAttribute("new_approximateloadtime").setValue(null);
Xrm.Page.getAttribute("nhs_holidayschedule").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfrequencycomments").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorresultserrorfile").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilename").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilecomments").setValue(null);
}
}
I believe it's time to learn how to debug webresources - blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools
Good luck!
My field that I am checking is a lookup
I think I am still missing something:
function AccumulatorIDOnChange() {
var fieldId = field.getValue();
if (field != null) {
var fieldOption = field.getText();
if (fieldOption != null)
return fieldId[0].name.toString();
else
return '';
}
}
var AccumulatorID = getOptionSetText("nhs_accumulatorsource");
if (AccumulatorID !='')
{
Xrm.Page.getAttribute("new_fileformat").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfilelayoutcomment").setValue(null);
Xrm.Page.getAttribute("nhs_programmingtype").setValue(null);
Xrm.Page.getAttribute("nhs_ftpprovider").setValue(null);
Xrm.Page.getAttribute("new_productionftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_productionfilename").setValue(null);
Xrm.Page.getAttribute("new_monday").setValue(null);
Xrm.Page.getAttribute("new_tuesday").setValue(null);
Xrm.Page.getAttribute("new_wednesday").setValue(null);
Xrm.Page.getAttribute("new_thursday").setValue(null);
Xrm.Page.getAttribute("new_friday").setValue(null);
Xrm.Page.getAttribute("new_saturday").setValue(null);
Xrm.Page.getAttribute("new_sunday").setValue(null);
Xrm.Page.getAttribute("new_approximateloadtime").setValue(null);
Xrm.Page.getAttribute("nhs_holidayschedule").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorfrequencycomments").setValue(null);
Xrm.Page.getAttribute("nhs_accumulatorresultserrorfile").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorftpdirectory").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilename").setValue(null);
Xrm.Page.getAttribute("nhs_resultserrorfilecomments").setValue(null);
}
doesn't work.
I think you have an issue here:
if (AccumulatorID != null || AccumulatorID != 'undefined' || AccumulatorID !='')
You have negation with Or, so I think this will always hit
Try adding this function:
function getOptionSetText(fieldName) {
var field = Xrm.Page.getAttribute(fieldName);
if (field != null) {
var fieldOption = field.getText();
if (fieldOption != null)
return fieldOption;
else
return '';
}
}
Then replace your if statement (and above line) as shown here:
var AccumulatorID = getOptionSetText("nhs_accumulatorsource");
if (AccumulatorID !='')
{
// Your logic here
}
If your field is not an option set (but a lookup), you can modify the following lines to this:
var fieldId = field.getValue();
if (fieldId != null)
return fieldId[0].name.toString();
Hope this helps.
When doing F12 and I put in break points on all of it, it hits all of them and nulls the fields even when the Accumulator Source field is not filled in.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156