0

I am trying to retrieve the date from a field (which is a user input field) in a Campaign Member, and give that value to a new date field.

{!REQUIRESCRIPT
("/soap/ajax/13.0/connection.js")}

var records = {!GETRECORDIDS($ObjectType.CampaignMember)};
var newRecords = [];

if (records[0] == null)
{
    alert("Please select at least one row")
}
else
{
    for (var n=0; n<records.length; n++) {
    var CampaignMemberObj = new sforce.SObject("CampaignMember");
    CampaignMemberObj.id = records[n]; 

    CampaignMemberObj.New_Start__c = new Date("{!CampaignMember.Course_Date__c}");

    newRecords.push(leadObj);
}
result = sforce.connection.update(newRecords);
if (result[0].success=='false') 
{   
    alert(result[0].errors.message);
} else 
{
location.reload(true);
}
}

An error is returned that of FaultString:"Nan... which indicates that it is not returning a number.

Any suggestions?

1
  • You're getting a string with this: {!CampaignMember.Course_Date__c} Can you do a console.log('{!CampaignMember.Course_Date__c}'); and reply back. You're probably going to have to parse the string into a JavaScript date.
    – Andrew L.
    Jul 5 '16 at 5:42
0

Look at the getDate() method on pictureenter image description here

Got it from https://success.salesforce.com/answers?id=90630000000gwhCAAQ

2
  • Thanks - but the above code gives oppty.CloseDate the value of TODAY. I want to take the date from an existing field (in my example it is CampaignMember.Course_Date__c and put it into another field (which is type date) in the above example this is CampaignMemberObj.New_Start__c
    – David
    Jul 5 '16 at 0:31
  • My fault, didn't read the given solution properly.
    – EvAzi
    Jul 5 '16 at 7:14
0

Thanks - but the above code gives oppty.CloseDate the value of TODAY.

I want to take the date from an existing field (in my example it is CampaignMember.Course_Date__c and put it into another field (which is type date) in the above example this is CampaignMemberObj.New_Start__c

So I need to take the value from "{!CampaignMember.Course_Date__c}" and put it into CampaignMemberObj.New_Start__c

Do you know how to do that?

1
  • This is not an answer, so please add a comment rather than answering. Jul 5 '16 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.