You need to sign in to do that
Don't have an account?
KD Teja
Create a record on Custom Object using onClick Javascript Button
Hello All,
Please help me to create a record on Custom Object using javascript button.
1. Whenever i click a button it should pick (accountid,ownerid,CloseDate) from Opportunity record
2. It should create a record with above fields on Custom Object.
===================================================
> The below code that i have written is throwing an error on chrome browser
(faultstring:'soapenv:Client',faultstring:''NaN-NaN-NaNTNaN:NaN:NaN:NaN-NaN:NaN' is not a valid value for the type xsd:date',)
> When i try this in IE it is giving me some other date in internet explorer
> I have tried so many things (parsing,format,toISOString,toLocaleDate..etc..,) but no luck.
===================================================
Code:
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var opp = new sforce.SObject("Opportunity");
opp.Account = "{!Opportunity.AccountId}";
opp.OwnerId = "{!Opportunity.OwnerId}";
opp.CloseDate = "{!Opportunity.CloseDate}";
alert(opp.CloseDate);
var ord = new sforce.SObject("Order__c");
ord.Account_Name__c = opp.Account;
ord.Account_Director_Name__c = opp.OwnerId;
if(opp.CloseDate==null || opp.CloseDate == ''){
ord.Customer_Signature_date__c = null;
} else {
var temp = new Date(opp.CloseDate);
ord.Customer_Signature_date__c = temp;
}
new_rec = sforce.connection.create([ord]);
alert('Opportunity Converted successfully ID : '+new_rec[0].id);
======================================================
Please correct me what is the wrong with my code. Every field is populating except CloseDate field.
Thanks in Advance
Please help me to create a record on Custom Object using javascript button.
1. Whenever i click a button it should pick (accountid,ownerid,CloseDate) from Opportunity record
2. It should create a record with above fields on Custom Object.
===================================================
> The below code that i have written is throwing an error on chrome browser
(faultstring:'soapenv:Client',faultstring:''NaN-NaN-NaNTNaN:NaN:NaN:NaN-NaN:NaN' is not a valid value for the type xsd:date',)
> When i try this in IE it is giving me some other date in internet explorer
> I have tried so many things (parsing,format,toISOString,toLocaleDate..etc..,) but no luck.
===================================================
Code:
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var opp = new sforce.SObject("Opportunity");
opp.Account = "{!Opportunity.AccountId}";
opp.OwnerId = "{!Opportunity.OwnerId}";
opp.CloseDate = "{!Opportunity.CloseDate}";
alert(opp.CloseDate);
var ord = new sforce.SObject("Order__c");
ord.Account_Name__c = opp.Account;
ord.Account_Director_Name__c = opp.OwnerId;
if(opp.CloseDate==null || opp.CloseDate == ''){
ord.Customer_Signature_date__c = null;
} else {
var temp = new Date(opp.CloseDate);
ord.Customer_Signature_date__c = temp;
}
new_rec = sforce.connection.create([ord]);
alert('Opportunity Converted successfully ID : '+new_rec[0].id);
======================================================
Please correct me what is the wrong with my code. Every field is populating except CloseDate field.
Thanks in Advance
Sorry for this issue you are encountering.
May I suggest you please check with below link from the stack exchange community exactly with a similar issue which might help you further.
- https://salesforce.stackexchange.com/questions/79533/salesforce-custom-button-onclick-javascript-create-multiple-child-record
Please let us know if this helps.Thanks,
Nagendra
Thanks for your reply, i have checked the suggested link and i tried. No luck. Here the above code is working but, am getting error only at date field. Without date field everything is populating.I need date field also get populated along with other fields.