最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CRM Xrm.Page.ui.formSelector.items.get() Returning Null - Stack Overflow

programmeradmin0浏览0评论

I wrote javascript code and added it as a form on load event of entity(contact). In that Code I want to navigate from the opening form to another form.

For previous developments, I'm trying to get the id of the opening form which I need in order to navigate. Code as shown below.

  var id = Xrm.Page.ui.formSelector.getCurrentItem().getId();

      if (itemid != null) 

    Xrm.Page.ui.formSelector.items.get(id).navigate();

Xrm.Page.ui.formSelector.getCurrentItem() function returns a null value. It doesn't get the item so I can't get the value. What's wrong with that code, what am I missing?

Thanks for replies in advance.

I wrote javascript code and added it as a form on load event of entity(contact). In that Code I want to navigate from the opening form to another form.

For previous developments, I'm trying to get the id of the opening form which I need in order to navigate. Code as shown below.

  var id = Xrm.Page.ui.formSelector.getCurrentItem().getId();

      if (itemid != null) 

    Xrm.Page.ui.formSelector.items.get(id).navigate();

Xrm.Page.ui.formSelector.getCurrentItem() function returns a null value. It doesn't get the item so I can't get the value. What's wrong with that code, what am I missing?

Thanks for replies in advance.

Share Improve this question edited Aug 14, 2014 at 13:41 CaptainBli 4,2114 gold badges42 silver badges59 bronze badges asked Aug 14, 2014 at 13:36 e_sezgine_sezgin 632 silver badges14 bronze badges 1
  • 2 Can you explain why you are checking itemid in your IF condition while you have assigned the value to id variable? – Scorpion Commented Aug 14, 2014 at 14:46
Add a ment  | 

3 Answers 3

Reset to default 3

You are assigning the value to id variable but checking itemid in your IF condition. In if condition just replace the if (itemid != null) with if (id != null)

To test your JavaScript. You can run following function:

var formItem = Xrm.Page.ui.formSelector.getCurrentItem();
if (formItem != null)
{
    var itemId = formItem.getId();
    var itemLabel = formItem.getLabel();
    alert(itemId + " | " itemLabel);
}
else
{
    alert("Unable to get current form");
}

Finally, to switch between form, following is very useful function which takes the form name as parameter. you can make changes to use form Id if you like.

function redirectToForm(formName) {
    var currentForm = Xrm.Page.ui.formSelector.getCurrentItem();
    if (currentForm != null) { 
        if (currentForm.getLabel().toLowerCase() != formName.toLowerCase()) { //make sure it's not already this form
            var availableForms = Xrm.Page.ui.formSelector.items.get();
            for (var i in availableForms) {
                var form = availableForms[i];
                if (form.getLabel().toLowerCase() == formName.toLowerCase()) {
                    form.navigate();
                }
            }
        }
    }
}

In My case, i prefer send the form name as parameter of a kind function such as constructor via load form function.

in the javascript code:

var Formname = "Default";
    function Initialize(formname)
    {
      Formname = formname;
    }

In customization of Form, in the onload function, you set this variable and this way remove the dependece from for selector ponent.

I hope that this solution can help many.

I took it up a notch and wrote the following post. You might find it interesting. http://totbcrm.blogspot.co.il/2014/08/working-with-multiple-forms.html

发布评论

评论列表(0)

  1. 暂无评论