Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

dynamics 365 online status reason field of opportunity.

(0) ShareShare
ReportReport
Posted on by 1,077

Hi All,

I am writing javascript to filter status reason field of opportunity using javascript.

my requirement is based on lookup field value show dependent status reason values.

I am using below code, but its not working, neither giving any error.


function fProduct()
{ debugger
var lookupfield = new Array;
lookupfield = Xrm.Page.getAttribute("parentaccountid").getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].id;
//alert('d'+lookupid);
var sFetch = "<fetch mapping='logical' version='1.0' distinct='false' output-format='xml-platform'>" +
"<entity name='account'>" +
"<attribute name='name'/>" +
"<attribute name='primarycontactid'/>" +
"<attribute name='new_products'/>" +
"<attribute name='accountid'/>" +
"<order attribute='name' descending='true'/>" +
"<filter type='and'><condition attribute='accountid' operator='eq' value='" + lookupid + "'/></filter>" +
"</entity>" +
"</fetch>";
var fetchedUser = XrmServiceToolkit.Soap.Fetch(sFetch);
if (fetchedUser == "")
return;
if(fetchedUser.length >0)
{
// alert('ff'+fetchedUser.length);
var varray = new Array();
for(var i=0; i<1; i++)
{
if(fetchedUser[i].attributes.new_products != null)
{
var value = new Array();
value[0] = new Object();
value[0].name = fetchedUser[i].attributes.new_products.name;
//alert('sf'+value[0].name);

if(value[0].name=="ABC")
{

var preferredTimeOptionSet = Xrm.Page.ui.controls.get("statuscode");
var optionsSets = preferredTimeOptionSet.getAttribute().getOptions();
preferredTimeOptionSet.clearOptions();

 preferredTimeOptionSet.addOption(optionsSets[0], 1);
 preferredTimeOptionSet.addOption(optionsSets[1], 2);

// alert('b');
}
else if(value[0].name=="XYZ")
{
var preferredTimeOptionSet = Xrm.Page.ui.controls.get("statuscode");
var optionsSets = preferredTimeOptionSet.getAttribute().getOptions();
preferredTimeOptionSet.clearOptions();
 preferredTimeOptionSet.addOption(optionsSets[2], 3);

// alert('c');
}
}
}
}

} else
{return;}

}

Note: as per debug this line is not working- 

preferredTimeOptionSet.clearOptions();

 

Kindly let me know whats wrong in script.

Thanks

*This post is locked for comments

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: dynamics 365 online status reason field of opportunity.

    Thanks Alex,

    tried as per you mention but my filter is still not working.

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: dynamics 365 online status reason field of opportunity.

    Actually, this seems to be working:

    function removeStatuses()

    {

    debugger;

           var preferredTimeOptionSet = Xrm.Page.ui.controls.get("statuscode");

           var optionsSets = preferredTimeOptionSet.getOptions();

           preferredTimeOptionSet.clearOptions();

           for (var i in optionsSets) {

              preferredTimeOptionSet.addOption(optionsSets[i]);

           }

    }

    But there are a few things:

    when you call preferredTimeOptionSet.getAttribute().getOptions(), you are getting options for the selected status (they are filtered)

    when you call preferredTimeOptionSet.getOptions(), there seem to be all of them (not pre-filtered for the status)

    removeOption does not work for some reason

    clearOptions works

    addOption works, it seems (at least it works if you do it as above)

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: dynamics 365 online status reason field of opportunity.

    Maybe that field is just special - others used to have problem with it as well(and that code does not work for me either somehow):

    community.dynamics.com/.../163650

    Create a custom option set, duplicate those options there, put it on the form, use the code with that field, and use a workflow/business rule to set the status code?

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: dynamics 365 online status reason field of opportunity.

    Check for custom field code is working, but for status code it is not working.

    Any one can let me know what is wrong.

    Thanks

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: dynamics 365 online status reason field of opportunity.

    Tried. But not working.

    Thanks

  • Suggested answer
    SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: dynamics 365 online status reason field of opportunity.

    just like you have but remove extra line

            var preferredTimeOptionSet = Xrm.Page.ui.controls.get("statuscode");

            var optionsSets = preferredTimeOptionSet.getAttribute().getOptions();

            for (var i in optionsSets) {

              if (i == 100000000 || i == 100000001) {

                  preferredTimeOptionSet.removeOption(optionsSets[i]);

              }

            }

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: dynamics 365 online status reason field of opportunity.

    Can you please send the code. I tried

    preferredTimeOptionSet.removeOptions();

    Its giving not supported error.

    Thanks

  • Suggested answer
    SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: dynamics 365 online status reason field of opportunity.

    remove      preferredTimeOptionSet.clearOptions();  before your

    for (var i = 0; i < optionsSets.length - 1; i++)

     line

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: dynamics 365 online status reason field of opportunity.

    Thanks for reply,

    tried remove also but not worked. Here is used code

    var preferredTimeOptionSet = Xrm.Page.ui.controls.get("statuscode");

                                   var optionsSets = preferredTimeOptionSet.getAttribute().getOptions();

                                   preferredTimeOptionSet.clearOptions();

    for (var i = 0; i < optionsSets.length - 1; i++) {

               if (i == 100000000 || i == 100000001) {

                   preferredTimeOptionSet.removeOption(optionsSets[i]);

               }

    }

  • Suggested answer
    SergiiChvyr Profile Picture
    SergiiChvyr on at
    RE: dynamics 365 online status reason field of opportunity.

    Hi,

    try get all options and then remove one by one using for() statement

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans