locked
Clearing lookup value using REST updateRecord() RRS feed

  • Question

  • Hi, I am writing custom javascript code to clear a lookup field, and then continuously check to see if the field has been populated.  A workflow is triggered to run once the lookup field has been changed and is set to place a new lookup value into the field.  Once the workflow populates the lookup field, the javascript code stops checking the field and opens the new record.

    Currently, I am using a REST SDK updateRecord call to clear the field, but it does not seem to be working from my check field function.  I can use a Xrm.Page.getAttribute().setValue() call to clear it, but then I need to save the record so the workflow can read it. 

    Xrm.Page.getAttribute("ber_recentquoteid").setValue(null);
    Xrm.Page.data.entity.save();
    timeout();

    After saving the page, the timeout() function call does not run.  So I am wondering if there is a way that I can use either the Xrm calls or the REST updateRecord to clear the field for my custom workflow to trigger

    function onClick() {
            var updatedQuoteHeader = {};
            updatedQuoteHeader.ber_RecentQuoteId = { Id: null, Name: null, LogicalName: null };
    
            SDK.REST.updateRecord(quoteHeaderId, updatedQuoteHeader, "ber_quoteheader",
                timeout(),   
                function (e) {
                    alert("REST call failed");
                }
            );
    }
    
    var myEmailGuid = null;
    
    function check_ber_recentquoteid() { 
        SDK.REST.retrieveMultipleRecords("ber_quoteheader", "$select=ber_RecentQuoteId&$filter=ber_quoteheaderId eq (guid'" + quoteHeaderId + "')&$top=1",
            function (quoteheader) {
                //alert("quoteheader[0].ber_RecentQuoteId: " + quoteheader[0].ber_RecentQuoteId);
                if (quoteheader[0].ber_RecentQuoteId.Id != null) {   //if it has a value, then assign myEmailGuid the GUID
                    //alert("assigned new email");
                    clearInterval(myInterval);
                    myEmailGuid = quoteheader[0].ber_RecentQuoteId.Id;
                    Xrm.Utility.openEntityForm("email", myEmailGuid);
                }
            },
            function (e) {
                alert(e);
            },
            function () {
                //alert("success");
            }
        );
    }
    
    var myInterval;
    
    function timeout() {
    
        myInterval = setInterval(function () {check_ber_recentquoteid();}, 5000);
    }
    

    Thanks for reading,

    Mitch

    Thursday, October 24, 2013 9:14 PM

Answers

  • Hi Mitch,

        Please add following line before save

    Xrm.Page.getAttribute("fieldname").setSubmitMode("always"); 


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Marked as answer by Mitch Gollub Wednesday, December 16, 2015 7:43 PM
    Thursday, October 24, 2013 9:59 PM