Home > apex > Error to populate lookup field onclick javascript

Error to populate lookup field onclick javascript

June 13Hits:5
Advertisement

I have below code which throws an error to populate lookup field ID value from one object to another. It unexpectedly tries to assign Name of Account object instead of ID. So it throws error. Can someone tell me why?

Javascript Code

 {!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}  //identify parent record  var FormR= new sforce.SObject("Form_Requests_abv__c"); FormR.id = '{!Form_Requests_abv__c.Id }'; FormR.name = '{!Form_Requests_abv__c.Name}';   // insert Sample Form transactions var SampleFormTrans= new sforce.SObject("Sample_Order_Form_abv__c");  //SampleFormTrans.Account_abv__c = "{!Form_Requests_abv__c.Account_abv__c}"; var s= document.getElementById('{!Form_Requests_abv__c.Account_abv__c}'); SampleFormTrans.Account_abv__c = s; var add= document.getElementById('{!Form_Requests_abv__c.Address_abv__c}'); //SampleFormTrans.Address_abv__c= '{!Form_Requests_abv__c.Address_abv__c}'; SampleFormTrans.Address_abv__c= add; var FR= document.getElementById('{!Form_Requests_abv__c.Id}'); SampleFormTrans.Form_Request_abv__c= FR; //SampleFormTrans.Form_Request_abv__c= '{!Form_Requests_abv__c.Id}'; SampleFormTrans.OwnerID= '{!Form_Requests_abv__c.OwnerId}'; SampleFormTrans.Quantity_abv__c= '{!Form_Requests_abv__c.Quantity_abv__c}'; //SampleFormTrans.Product_abv__c='{!Form_Requests_abv__c.Product_ID_abv__c}'; //SampleFormTrans.Form_template_abv__c='{!Form_Requests_abv__c.Form_Template_Name_abv__c}'; var FT= document.getElementById('{!Form_Requests_abv__c.Form_Template_Name_abv__c}'); SampleFormTrans.Form_Template_Name_abv__c= FT;  //get query var query = "SELECT  Account_abv__c ,Address_abv__c,Form_Request_abv__c, "+ "OwnerID, Quantity_abv__c, Product_abv__c, Form_template_abv__c, Id FROM "+ "Sample_Order_Form_abv__c WHERE Form_Request_abv__c='{!Form_Requests_abv__c.Id}'";  var records = sforce.connection.query(query);  alert(records); var records1 = records.getArray('records'); alert(records1); if(records[0]==null)     {alert('New record to insert'); var result = sforce.connection.create([SampleFormTrans]);} if(result[0].getBoolean("success")) {    alert('Sample Form Transaction inserted successfully');    window.location.reload(); } else{   alert('Error : '+result); }  var formId = '{!Sample_Order_Form_abv__c.Id}';  var expired = '{!Sample_Order_Form_abv__c.Expired_abv__c}';  var templateId = '{!Sample_Order_Form_abv__c.Form_template_Id_abv__c}';  if(expired == '1'){  alert("Form expired. Print option not available.");  }else{ window.open('/apex/FormTemplatePrinter?ids='+formId+'&TemplateId='+templateId,'_blank');  } 

Error

Successfully created but all lookup field values are blank.

Answers

Remove all document.getElementById('{!Form_Requests_abv__c.Form_Template_Name_abv__c}');

and add like this

SampleFormTrans.Product_abv__c='{!Form_Requests_abv__c.Product_ID_abv__c}';

this will contain your id

So just assign the Id

Like this

var SampleFormTrans= new sforce.SObject("Sample_Order_Form_abv__c");

SampleFormTrans.Account_abv__c = "{!Form_Requests_abv__c.Account_abv__c}";

SampleFormTrans.Address_abv__c= '{!Form_Requests_abv__c.Address_abv__c}';

SampleFormTrans.Form_Request_abv__c= '{!Form_Requests_abv__c.Id}';

SampleFormTrans.OwnerID= '{!Form_Requests_abv__c.OwnerId}';

SampleFormTrans.Quantity_abv__c= '{!Form_Requests_abv__c.Quantity_abv__c}';
SampleFormTrans.Product_abv__c= '{!Form_Requests_abv__c.Product_ID_abv__c}';
SampleFormTrans.Form_template_abv__c='{!Form_Requests_abv__c.Form_Template_Name_abv__c}';

After discussion with OP Found he was using wrong Field API Name..

var SampleFormTrans= new sforce.SObject("Sample_Order_Form_abv__c"); 

SampleFormTrans.Account_abv__c = '{!Form_Requests_abv__c.Account_abvId__c}'; 

SampleFormTrans.Address_abv__c= '{!Form_Requests_abv__c.Address_abvId__c}'; 

SampleFormTrans.Form_Request_abv__c= '{!Form_Requests_abv__c.Id}'; 

SampleFormTrans.OwnerID= '{!Form_Requests_abv__c.OwnerId}'; 

SampleFormTrans.Quantity_abv__c= '{!Form_Requests_abv__c.Quantity_abv__c}'; 

SampleFormTrans.Form_template_abv__c='{!Form_Requests_abv__c.Form_Template_Name_abvId__c}';

Related Articles

  • Error to populate lookup field onclick javascriptJune 13

    I have below code which throws an error to populate lookup field ID value from one object to another. It unexpectedly tries to assign Name of Account object instead of ID. So it throws error. Can someone tell me why? Javascript Code {!REQUIRESCRIPT("

  • Is it possible to populate lookup field using Workflow or Process builder?October 1

    Is is possible to populate lookup field using Workflow or Process builder? I want to populate the lookup field based on the value of another field which is not lookup. --------------Solutions------------- I think the easiest way to do this is to use

  • Populate lookup field on Object after Clicking a custom button and creating record on different objectFebruary 14

    I would like to create a custom button on service contract to create an opportunity. I want to populate a lookup field between service contract and opportunity (So I will be able to use it for some formula fields later on) The steps are: Sales rep cl

  • Getting started on Apex - populate lookup field via SoQLApril 5

    I am looking to use an Apex Class in a Visualforce page that populates a field based on the result of a SoQL query. The idea is that I am making a custom Save And Do X button which must be available before a record is saved, hence needing a VFpage. I

  • Populate Lookup field on Opportunity upon Lead ConversionMay 21

    I am trying to populate a Contact lookup field (Sourced_By__c) on the Opportunity with the Converted Contact upon Lead Conversion but am not having any luck. I do not get an error but it also does not populate the field. Here is my trigger below, can

  • SharePoint 2013: How to update multi-value lookup field using JavaScript CSOMSeptember 17

    I have a Contacts list which has a multi-value lookup field called ContactType. The result of a CAML query will show the following value for ContactType for one of the list items: 1;#Applicant;#2;#Employee I had a look at Fiddler after executing a CS

  • access additional lookup fields using JavaScript and CSOM

    access additional lookup fields using JavaScript and CSOMMarch 11

    In visual studio I have added lookup field (SubMenuItemIdRefTitle) to list definition listA that references ListB. I have also added <ViewFields> <FieldRef Name="Attachments"></FieldRef> <FieldRef Name="LinkTitle"&

  • Before Insert Trigger Populate Lookup FieldFebruary 6

    I have a very simple trigger that for some reason doesn't want to work. Using a before insert trigger, I want to populate a lookup field on a grandchild object with the grandparent objects OwnerId. When I try it, nothing happens. If you know why, can

  • SharePoint designer REST call to populate lookup field in SharePoint 2013 listMay 27

    I'm trying to update a multi-value lookup field in a SharePoint 2013 list from a SharePoint designer workflow using the 'Call HTTP Web Service' action. Here's how the field looks when querying a list item with two values: "Assigned_x0020_toId":{

  • Trigger to populate lookup fieldOctober 30

    I have a custom object Service Request with a lookup field of Account.Service Request has one more field called Web Email(Email type).I need a trigger to search accounts with the same value in web email and populate the lookup field on service reques

  • Auto-populate lookup fieldsApril 26

    I have a standard Object (ServiceContract) which has a Master-Detail relation with ContractLineItem (also a standard object). ContractLineItem further has a master-Detail relation with a custom object - TransactionLineItem. When i click on "New Trans

  • How to Populate lookup field values between case and custom object

    How to Populate lookup field values between case and custom objectDecember 15

    I have Standard Object: Case, which has look up field VIN__c(Field) with Custom Object VEH_Veh__c. My aim is when i select Vin number(VIN__C) from case, such that model,brand from VEH_Veh__c should be displayed according to the vin number selected in

  • Populate Lookup field to user on one of the object based on multipicklist value criteria of related recordsApril 12

    I have 2 object A and B,both have lookup relationship where A is parent. A has one field X which is lookup to user B stores the Sales member records and other details It has fields like ULP--->Lookup to user Type-->Picklist P1,P2 MultiPicklist-->

  • Error when I populate lookup with external id using .put methodJuly 3

    You can populate lookup fields using an object with an external id field populated like so: Custom_Object__c o = new Custom_Object__c(Account__r=new Account(External_ID__c='123')); insert o; However, when I want to dynamically assign values using the

  • Unexpected Identifier for Onclick Javascript buttonJanuary 21

    I created a custom button for custom object to place in the related list. The custom object has two look-ups, one for case and one for account. This button, when clicked, should open in a new window to save a record of the custom object, with the def

  • how to auto popluation of lookup field in vfpageFebruary 18

    I have two custom objects A and B contains same lookup field in both objects when i select lookup field object A it Should populate selected value in object B when i select Object B in the related list of objectA. --------------Solutions-------------

  • How to pass lookup values from one object to another object's lookup field using triggerFebruary 1

    here is my code in which i am trying to pass lookup values and owner so that i can create an order record. but i m facing error for contractor lookup field-- " Error: Compile Error: Illegal assignment from Id to Contract at line 11 column 15" an

  • Get the ID of a lookup field for Onclick Javascript ButtonSeptember 25

    I am trying to get the ID of a lookup field so I can populate a field on a new record that is created when an Onclick Javascript button is clicked. Basically I need the ID of Birth_Record_c.Dame_c instead of the value so I don't get the Malformed ID

  • JavaScript Error when typing in lookup field

    JavaScript Error when typing in lookup fieldOctober 12

    I am receiving this javascript error in an up-to-date version of Google Chrome (Version 45.0.2454.101 m): error: {faultcode:'soapenv:Client', faultstring:'Attribute "xmlns" bound to namespace "http://www.w3.org/2000/xmlns/" was already

  • Javascript to add an "Add new Item" to Lookup fields on an Edit Form is not working in Chrome and MozillaNovember 10

    The below javascript which creates a link next to a lookup field on a list NewForm or EditForm. It is working fine in IE and when lookup has more than 20 + values it is not working in Chrome as the input Title is converting it to Select. This script

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.857 s.