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
SeawardTSeawardT 

Search multiple Asset Fields, then display on Field on Case layout

Our organization requires active support which is listed by asset. There are typically multiple assets associated with an Account, however I want to search through all the Assets in an Account and if the term Active is found in the Status field, then show "Active", otherwise if it is not found display "Expired".

I've tried creating a case field using a forumla to try an IF statement, however I cannot access the related Asset fields.

Obviously, this would seem I need to create a S-Control in order to have this happen when an Account is associated with a case. Seems simple, but I can't get my page to load this.
Angel118Angel118
Hi SeawardT,
                       So, do you want to check all the related items under the Account if any of the records contain Status = Active, then update the Account Status fields as Active else Expired, Correct ?


If it is so,  Then u need to write a S-Control something like this.
Code:
<script type="text/javascript" src="/soap/ajax/10.0/connection.js" >
</script>
<script type="text/javascript">
var Account_Id = '{Account.Id}';

var Assets = sforce.connection.query("select Id, Status Asset where AccountId= '"+Account_Id+"'");
var AssetDetailsArray = Assets.getArray("records");
if(AssetDetailsArray.length>0)
{
for(var i=0;i<AssetDetailsArray.length;i++)
{
var AssetStatus = AssetDetailsArray[i].Status__c;
if(AssetStatus =='Active')
{
var _AccountUpdate = new sforce.SObject("Account");
_AccountUpdate.Id = "+Account_Id+";
_AccountUpdate.Status ="Active";
var UpdateResult = sforce.connection.update([_AccountUpdate]);
}
else
{
var _AccountUpdate = new sforce.SObject("Account");
_AccountUpdate.Id = "+Account_Id+";
_AccountUpdate.Status ="Expired";
var UpdateResult = sforce.connection.update([_AccountUpdate]);
}
}
}
window.parent.location.href="{!URLFOR($Action.Account.View,Account.Id)}";
</script>

 Let me know, if it works or any errors come in, we will rectify them together..:smileywink:


Angel..

SeawardTSeawardT
This looks like this is definately close. In order to follow this, do I need to create a custom object "_AccountUpdate" and then create fields (ID and Status)? Or are these created on the fly?

My follow up question, then is now once this data is obtained, how is it is moved to a case? Should this field be populated into an Account field, then somehow it needs to be moved to a case along with the Account Name?

Finally, just a quick one, should this S-Control be HTML or Snippet?

Also, thanks so much so far! This is a great help to understanding the logic.

Message Edited by SeawardT on 10-15-2007 08:53 AM

Angel118Angel118
HI SeawardT,
                       No u need not create a custom object, _AccountUpdate and create any fields.
 
You need to have a new control to create a case or can create a case from the related list of the Account.
 
This is a HTML.
 
Cheers Angel...
SeawardTSeawardT
That sounds great. But how do I use the UpdateResult?

Maybe:

Account.Status = UpdateResult

Message Edited by SeawardT on 10-15-2007 11:48 AM

Angel118Angel118
No, UpdateResult is not be used anywhere, except u waana paas the same  updated values somewhere else in the Control.
 
Cheers
Angel...
SeawardTSeawardT
Then how do I get the Active or Expired fields to show in either the Account or the Case? Perhaps that is where I am confused. Just to ensure I have explained what I am trying to do, ill give another go:

Query Status field in all Assets which are associated with an account for "Active"
If "Active" is found in 1 or more Assets, then "Active" would show up in a field under the Account Page Layout
If no "Active" is found in any Asset under the Account, then show "Expired" would show in the field under the Account

Then when a case is opened and an Account is associated with the case, that field would populate with either "Active" or "Expired" based on the field in the Account the say way a Phone number or email would show up for the contact.

So..
From the example, this looks great, but is only half way. This seems to be a good way to query the Assets, however, I am unclear as how to access the result in a tangeable way. I added this S-Control (html) to the Account layout, but how to get that result to display is something I am still working on. I tried using the above mentioned method to output to a variable, but was of course unsuccessful.

Lastly, I am still hesitent on what method to use to being the process. Assign it to a button or link? I would like this to happen without any interaction except loading the Account page.

Thoughts?