0

I have the scenario, on Asset I have related list of Work Order and On Work Order having related list Work Order Accessories.

If I am on Asset, select any Work Order, and trying to add Work Order Accessories, I am not able to get Work Order ID. I am using WorkspaceAPI to get the data, and developing Lighting component for Adding Work Order Accessories.

enter image description here

sforce

enter image description here

enter image description here

Could anybody help me, how can I get it.

3
  • Where is the button located? On the related list? Apr 13, 2020 at 12:15
  • @ShaileshPatil Yes I have created button in related Object and it is in related List and tried to set data in query parameter like this /lightning/cmp/c__SD_ManageWorkOrderAccessory?workOrderId={!SD_Work_Order__c.Id}, but not setting it up. Apr 13, 2020 at 12:28
  • Ok... So getting an ID using a sophisticated standard way is not possible currently(Till last time I used). I am adding a hack way to obtain the parentID from the related list. Adding it in the answer. Please check and see if it fits your requirements. Apr 13, 2020 at 12:39

1 Answer 1

0

Please find the below code. I am not the owner of this code and it is a hack way.

    var value = helper.getParameterByName(component , event, 'inContextOfRef');  
/*This method fetch the parent record Id.*/
    getParameterByName: function(component, event, name) {
        name = name.replace(/[\[\]]/g, "\\$&");
        var url = window.location.href;
        var regex = new RegExp("[?&]" + name + "(=1\.([^&#]*)|&|#|$)");
        var results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }
19
  • Thanks for the reply, in Init should I do it?.. Apr 13, 2020 at 13:20
  • Yes. You can do. Apr 13, 2020 at 13:33
  • Bad Luck, not working for me....is it working for you..... Apr 13, 2020 at 13:37
  • Yep. Its an old implementation and working fine. Is it possible for you to post the LC code? Apr 13, 2020 at 13:38
  • 1
    var pageRef = component.get("v.pageReference"); var state = pageRef.state; // state holds any query params var base64Context = state.inContextOfRef; console.log("^^^^^^^^^^^^^^^State^^^^^^^^^^"+JSON.stringify(state)); if (base64Context.startsWith("1\.")) { base64Context = base64Context.substring(2); } var addressableContext = JSON.parse(window.atob(base64Context)); console.log("^^^^^^^^^^^^^^^^^^^^^^^^^"+addressableContext.attributes.recordId); Apr 14, 2020 at 6:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .