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

Javascript custom button

I"m trying to create a custom button on a case (attached to an opportunity), to add over the contact roles which are associated to that oppty to the case. Here's the code I have but I'm not sure how to amend it to work for all contact roles and not just the primary.



function getBaseURL() {
//This function will return the base part of the current window's URL without the trailing slash.
//Example Return Value: ""

	var fullURL = window.parent.location.href;
	var slashPosition = fullURL.indexOf("/", 9);
	var baseURL;
	if (slashPosition < 0)
		baseURL = fullURL;
		baseURL = fullURL.substr(0, slashPosition);
	return baseURL;

function doQuery() {
	var result = sforce.connection.query("select Id, OpportunityId, ContactId, Role, IsPrimary from OpportunityContactRole where OpportunityId = '{!}' and IsPrimary = true");
	var records = result.getArray("records");

	if (records.length > 0)
		window.parent.location.href = getBaseURL() + "/_ui/core/email/author/EmailAuthor?p2_lkid=" + records[0].ContactId + "&rtype=003&p3_lkid={!}&retURL=%2F{!}";
		if (confirm("ERROR: There is no Primary Contact specified yet for this opportunity. Click OK to specify one now."))
			window.parent.location.href = getBaseURL() + "/p/opp/ContactRoleEditUi/e?oppid={!}&retURL=%2F{!}";


Have you tried removing this portion of the query in the doQuery function:

and IsPrimary = true"