web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Cannot read property 'indexOf' of null in addCustomView UCI

(0) ShareShare
ReportReport
Posted on by

Hi experts!

i am getting this error "Cannot read property 'indexOf' of null" while using addCustomView in Dynamic 365 CRM UCI and register this event on change of this field "poc_vehicles"

Code:

function defaultToPurchasedVehicles(executionContext) {

var attribute = "poc_vehicles";
var formContext = executionContext.getFormContext();
var viewId = "{DDE2FB22-52C7-EA11-A812-000D3AB5D04F}";
var entityName = "sl_vehicle";
var viewDisplayName = "Purchased vehicles";
var isDefault = true;

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
fetchXml += "<entity name='sl_vehicle'>"
fetchXml += "<attribute name='sl_name' />"
fetchXml += "<attribute name='sl_yearnumber' />"
fetchXml += "<attribute name='sl_registrationnumber' />"
fetchXml += "<attribute name='sl_model' />"
fetchXml += "<attribute name='sl_make' />"
fetchXml += "<attribute name='sl_vehicleid' />"
fetchXml += "<order attribute='sl_name' descending='false' />"
fetchXml += "<filter type='and'>"
fetchXml += "<condition attribute='statuscode' operator='eq' value='1' />"
fetchXml += "</filter>"
fetchXml += "<link-entity name='contact' from='contactid' to='sl_vehiclesid' link-type='inner' alias='ab'>"
fetchXml += "<filter type='and'>"
fetchXml += "<condition attribute='sl_vehiclepurchasestatus' operator='in'>"
fetchXml += "<value>{8C17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "<value>{8D17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "<value>{8E17A6FF-07A4-E911-A837-000D3AB18F6D}</value>"
fetchXml += "</condition>"
fetchXml += "</filter>"
fetchXml += "</link-entity>"
fetchXml += "</entity>"
fetchXml += "</fetch>";

var layoutXml = "<grid name='resultset' object='4230' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='userqueryid'>" +
"<cell name='name' width='300 />" +
"<cell name='ownerid' width='100' />" +
"<cell name='modifiedon' width='100' />" +
"</row>" +
"</grid>";

formContext.getControl(attribute).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
}


Regards,
ZG

I have the same question (0)
  • Wahaj Rashid Profile Picture
    11,323 on at

    Hi,

    Did you make sure Execution Context is being passed?

    Also, the attribute (poc_vehicles) is available on the form?

    Best,

    Wahaj

  • ZeeshanGhause Profile Picture
    on at

    Thanks but i have added these checks


    if ((attribute != "" && viewId != "" && entityName != "" && viewDisplayName != "" && fetchXml != "" && layoutXml != "" && isDefault != false) && (attribute != null && viewId != null && entityName != null && viewDisplayName != null && fetchXml != null && layoutXml != null && isDefault != false)) {
    formContext.getControl(attribute).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
    }

    still getting same error
    see

    pastedimage1594905103192v1.png

  • Verified answer
    Wahaj Rashid Profile Picture
    11,323 on at

    Hi,

    Can you check following line in layoutXML:

    "<row name='result' id='userqueryid'>"

    I guess id should be name of the id field of 'sl_vehicle' entity for example 'sl_vehicl_id', can you try?

    Best,

    Wahaj

  • ZeeshanGhause Profile Picture
    on at

    i just created layout xml of view from xrmtool and then it works

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans