function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IZavalunIZavalun 

How to get full string in the 'value' property of the button control and not only the first word

Please look at the 2 lines bellow and help me to understand why:
 
- value of the _name in first line = "Brett's Industrial Account"
- value of the _name in the second line = "Brett"
 
How to fix this one?
I will really appriciate your help.
 
============================================================
alert(_name);
output = "<input id=btn1 type=button name=btn1 onclick=\"" + fn + "\" value='" + _name + "'>";
Ron HessRon Hess
it's probably the apos, try 

+ escape(_name) +
IZavalunIZavalun
After i did escape(_name), the value of the button appeared like this:
"Brett%27s%20Test%20Industrial%20Dist."
 
Is it something else I can try?
Thanks for the support
Michael SnowMichael Snow
"<input id=btn1 type=button name=btn1 value=\"" + _name + "\">";
The apostrophes around _name were the problem.  If you use quotes instead, then the apostrophe in the middle of your value will be displayed.
IZavalunIZavalun

Mike.

Thank you very much it worked.

Mike now I have the last ptoblem here if it's something  quick I will really appriciate if you can help me:

I am trying to update the 'Account' object with the Primary_distributor__c(lookup field) and Primary_Distributor_Location__c and reload the page and I am getting the error:

{errors:{fields:'Primary_Distributor__c', message:'Primary Distributor: id value of incorrect type: test diane', statusCode:'MALFORMED_ID'}, id:null,success:'false',}

===MY CODE=======

 

function cm(_name,_street,_city,_state,_id) {
alert("You Selected: " + "'" + _name + "'" + " in " + _city + ", " + _state);

if (_name) {
  var _IsMatch = new sforce.SObject("Account");
  _IsMatch.Id = _id;
  _IsMatch.Primary_Distributor__c = _name;
  _IsMatch.Primary_Distributor_Location__c = _city + ", " + _state;
  //_IsMatch.BillingState = _state; 
  var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
  if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
   alert("Successfully updated contact name!"); //indicate that the update was successful
   window.opener.location.reload();
  } else {
   alert("Error:\n"+updateIsMatch[0]); //display the error
  }
 }

}

Michael SnowMichael Snow
The data type for your custom field "Primary_Distributor__c" is an ID and not a string name.  You will have to look up the ID for the object and pass that to the Account object.  Assuming your custom object is named the same as the custom field from account, then...
"Select ID from Primary_Distributor__c where name = '"+_name+"'
IZavalunIZavalun

Mike,

There is no custom object - 'Primary_Distributor__c' is in the account object but the 'RecordTypeId=012600000004w6TAAQ'

The screen I am trying to update also Account object but the 'RecordTypeId=012600000004w6UAAQ'

 

 

Michael SnowMichael Snow
What is Primary_Distributor__c?  Is it an Account?
Then...

Code:
function cm(_name,_street,_city,_state,_id) {
alert("You Selected: " + "'" + _name + "'" + " in " + _city + ", " + _state);

if (_name) {
  var _PDId = "";
  var _GetNameQueryResult = sforce.connection.query("Select ID from Primary_Distributor__c where name = '"+_name+"');
  if(_GetNameQueryResult.size > 0)
  {
    var _NameRecs = _GetNameQueryResult.getArray('records');
    _PDId = _NameRecs.Id;
  }
  var _IsMatch = new sforce.SObject("Account");
  _IsMatch.Id = _id;
  _IsMatch.Primary_Distributor__c = _PDId;
  _IsMatch.Primary_Distributor_Location__c = _city + ", " + _state;
  //_IsMatch.BillingState = _state;
  var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
  if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
   alert("Successfully updated contact name!"); //indicate that the update was successful
   window.opener.location.reload();
  } else {
   alert("Error:\n"+updateIsMatch[0]); //display the error
  }
 }

}

 

Michael SnowMichael Snow
Sorry, change:
Select ID from Primary_Distributor__c where name = '"+_name+"

to:
Select ID from Account where name = '"+_name+"




IZavalunIZavalun

Mike,

Here is the first qrdr that works for me:

================================

var qrdr = sforce.connection.query("select Id, Name, BillingStreet, BillingCity, BillingState from Account where RecordTypeId='012600000004w6TAAQ' and Name like '" + tt + "%' and BillingState='" + s + "'");

================================

so, the 'Id' is available for me:

===============================

var fn = "cm(";
fn += ((_name && _name != null) ? "'" + _name + "'" : null) + ",";
fn += ((_street && _street != null) ? "'" + _street + "'" : null) + ",";
fn += ((_city && _city != null) ? "'" + _city + "'" : null) + ",";
fn += ((_state && _state != null) ? "'" + _state + "'" : null) + ",";
fn += "'" + _id + "');";

output = "<input id=btn1 type=button name=btn1 onclick=\"JavaScript:" + fn + "\" value=\"" + _name + "\">";

html += output;

==============================

when the button clicked all values passed to cm function: Please note I've got the Primary_Distributor_Location__c field working but getting the error to do the _IsMatch.Primary_Distributor__c = _name; because it's a reference field still to the 'Account' object

=====================================

function cm(_name,_street,_city,_state,_id) {
alert("You Selected: " + "'" + _name + "'" + " in " + _city + ", " + _state);
str_id='{!Account.Id}';

if (_name) {
  var _IsMatch = new sforce.SObject("Account");
  _IsMatch.Id = str_id;
  _IsMatch.Primary_Distributor__c = _name;
  _IsMatch.Primary_Distributor_Location__c =  _city + ", " + _state;
  
  var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
  if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
   alert("Successfully updated!"); //indicate that the update was successful
   window.close();
   window.opener.location.reload();
  } else {
   alert("Error:\n"+updateIsMatch[0]); //display the error
  }
 }

}
=================================

ERROR:

{errors:{fields:'Primary_Distributor__c', message:'Primary Distributor: id value of incorrect type: test diane', statusCode:'MALFORMED_ID'}, id:null,success:'false',}

Michael SnowMichael Snow
Try this:
Code:
function cm(_name,_street,_city,_state,_id) {
alert("You Selected: " + "'" + _name + "'" + " in " + _city + ", " + _state);
str_id='{!Account.Id}';

if (_name) {
  var _PDId = "";                                                                               
  var _GetNameQueryResult = sforce.connection.query("select Id from Account where RecordTypeId='012600000004w6TAAQ' and Name like '" + _name + "%' and BillingState='" + _state + "'");
  if(_GetNameQueryResult.size > 0)
  {
    var _NameRecs = _GetNameQueryResult.getArray('records');
    _PDId = _NameRecs.Id;
  }
  var _IsMatch = new sforce.SObject("Account");
  _IsMatch.Id = str_id;
  _IsMatch.Primary_Distributor__c = _PDId;
  _IsMatch.Primary_Distributor_Location__c =  _city + ", " + _state;
  
  var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
  if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
   alert("Successfully updated!"); //indicate that the update was successful
   window.close();
   window.opener.location.reload();
  } else {
   alert("Error:\n"+updateIsMatch[0]); //display the error
  }
 }

}