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 alert based on IF task.subject field

Hi all,


I'd like to add a javascript alert to an opportunity page. I've gotten it to be able to alert if criteria are met on Opportunity fields, but what about including Task information in this criteria?


i only want the alert to go off if there isn't a task on the opp page that has the word "approved" or "approval" in it. What can I add as the var task to do this?


Thanks so much for anyone who can steer me in the right direction. I'm pretty new to this, (clearly..)



function throwalert()
    // Begin by creating 3 variables for the criteria to be met.
    var oppname = "{!Opportunity.Name}";
    var isstatus = "{!Opportunity.StageName}";
    var quoteest = "{!Opportunity.Quote_Estimate__c}"
    quoteest = quoteest.replace(/[^\d\.]/g, "" ); // strip out all non-numeric characters
    quoteest = parseFloat( quoteest );

    var msgg = "The quote estimate for this opportunity is equal to or greater than $50,000. Remember to submit this opportunity for approval. ";

    var task = ??????????

   if ((quoteest >= 50000) && (isstatus == "Proposal/Price Quote"))
        window.parent.location.replace = "{URLFOR($Action.Opportunity.View, Opportunity.Id,null,true)};"






   Since an opportunity may have more than one tasks we need to look out for each tasks. Hence a query to task table would do here. Following may help with your req.


var isApproval = new Boolean(false); var taskResult = sforce.connection.query("Select Id, Subject from Task where whatId = '"+'{!Opportunity.Id}'+"' AND (Subject like 'Approv%' OR Subject like 'approv%')"); if( taskResult.size > 0 ){ isApproval = new Boolean(true); }

 the variable isApproval will determine if there are any tasks with subject having 'Approv*' and you can use this variable for your use.

hope this helps.




im having trouble putting it all together.


and at first it said that function requirescript could not be used in this formula. after some searching i reformatted it to:


<apex:includeScript value="/soap/ajax/17.0/connection.js"/>

<apex:includeScript value="/soap/ajax/17.0/apex.js"/>


but i am having trouble getting the functionality to work properly.


thanks very much and my apologies for my ignorance.