locked
Update Originating Lead on Account Form Using JavaScript? RRS feed

  • Question

  • Hi All,

    I have a requirement that when i click on Account Ribbon Button it should clear the "Originating Lead" Field on Account Form. I Wrote Javascript function to clear the field. When i click on this it seems cleared. But after still it is having its original value. Iam not knowing why it was not updating.Can any one help me regarding this context.

    Thursday, January 24, 2013 7:16 AM

Answers

All replies

  • Try using the following code just after the line where you are clearing the field value.

    Xrm.Page.getAttribute("<your-field-name>").setSubmitMode("always");

    Piyush

    Thursday, January 24, 2013 7:21 AM
  • Hi,

     Thanks for ur reply.

     I already tried that one...it is not working

    Thursday, January 24, 2013 7:23 AM
  • Can you share the code snippet so that people on the forums can take a look at what exactly you are trying to do.

    Piyush

    Thursday, January 24, 2013 7:27 AM
  • function AccountSave() 
    {
        if (event.Mode == 1 && Xrm.Page.getAttribute("dynamics_isreadyforintegration").getValue() == true) 
        {
            if ((Xrm.Page.data.entity.attributes.get("originatingleadid").getValue() != null) && (Xrm.Page.data.entity.attributes.get("territoryid").getValue() != null)) 
            {
                var LeadId;
                var TerritoryId;
                var lookupObject = Xrm.Page.getAttribute("originatingleadid");
                var lookupObject1 = Xrm.Page.getAttribute("territoryid");
                if ((lookupObject != null) && (lookupObject1 != null)) 
                {
                    var lookUpObjectValue = lookupObject.getValue();
                    var lookUpObjectValue1 = lookupObject1.getValue();

                    LeadId = lookUpObjectValue[0].id;
                    TerritoryId = lookUpObjectValue1[0].id;
                    alert(LeadId);
                    alert(TerritoryId);
                }
                Xrm.Page.getAttribute("new_leaddummy").setValue(LeadId);
                Xrm.Page.getAttribute("new_territorydummy").setValue(TerritoryId);
                Xrm.Page.data.entity.attributes.get("originatingleadid").setValue(null);
                Xrm.Page.data.entity.attributes.get("territoryid").setValue(null);
            }
            else 
            {
                //
            }
        }
    }
    Thursday, January 24, 2013 7:28 AM
  • After clearing the field value,try adding the below 2 lines,

    Xrm.Page.getAttribute('attribute_name').setSubmitMode("always");
    Xrm.Page.data.entity.save();

    • Proposed as answer by VikkyVignesh Thursday, January 24, 2013 7:35 AM
    Thursday, January 24, 2013 7:34 AM
  • Hi Sasank, I see that you are not saving the form anywhere. Try using

    Xrm.Page.data.entity.save();


    Piyush

    Thursday, January 24, 2013 9:10 AM
  • Hello,

    Based on the SDK originleadid field is not valid for update so the only option to clear field is direct SQL Update.


    Freelance Developer for Dynamics CRM 4.0/2011

    Sunday, January 27, 2013 12:59 PM
    Moderator