Few days back I came across a requirement that was interesting and new. So, I tried to implement it at my end and now I am sharing the solution with you all.
Requirement:
On click on of a button a prompt should come that takes input from the user. Based on user input I need to create an opportunity. But if opportunity with same name already exists then it should again ask for input and it should go on till user inputs a unique name and records are created successfully.
I hope I am clear with the requirement.
Initial thoughts:
There are couple of ways to get user input. One is to show popup applet which is better and sophisticated way to do it. Other is to user “prompt” function which is rather simple way to do it. I chose simple way that is “prompt” method to do it.
Solution:
I choose Opportunity List Applet to achieve this requirement.
Create a button control on this Applet and set the Method Invoked to EventMethodCreateOpty.
![]()
Note: I used this method name so that I don’t have script in PreCanInvoke method enable the button. To get more details about this method read the following post.
Now go to the browser script Applet_PreInvokeMethod of this Applet and write the following code
if(name == "EventMethodCreateOpty")
{
var lp = 1; //variable controling the loop
while(lp) //loop while user doesn't provide the unique name
{
CreateOpty();
if(theApplication().GetProfileAttr("OptyExsits") == "Y")
{
alert("Opportunity Already Exsists with same name. Please enter a new Name");
}
else
{
lp = 0; // end loop once you get the opty created
alert("Opportunity Created");
}
}
}
The Code for CreateOpty function is like:
function CreateOpty()
{
var optyname = prompt("Please Enter New Opportunity Name");
if(optyname == "null" || optyname == null) // in case user clicks cancel button
{
return(0);
}
var inp = theApplication().NewPropertySet();
var outp = theApplication().NewPropertySet();
var svc = theApplication().GetService("CreateOpty"); // call the BS and pass user input
inp.SetProperty("OptyName",optyname);
svc.InvokeMethod("CreateOppty",inp,outp);
}
I will be calling a BS to do my job though you can just set a profile attribute in browser script, let the execution resume and create records by scripting on Opporutnity BC but the problem there will calling the browser script again if Opportunity already exsists hence calling a BS is the only viable option here.
Now, I guess as everybody knows that to call a BS from browser script you need to create an entry in CFG file. So, just open your web client CFG file and go to [SWE] Section and create an entry for your BS.
In this case your CFG entry will look like ClientBusinessServiceX = “CreateOpty”
Where X is the one more than the number given to the last entry
Now Go to Siebel Tools > Business Service Section
Create a New Record with name as CreateOpty
Right click this record and choose Edit Server Script
Your Business Service PreInvoke Method should something like
The code for CreateOppty Function is something like
function CreateOppty(&Inputs)
{
var OpptyBO = TheApplication().GetBusObject("Opportunity");
var OpptyBC = OpptyBO.GetBusComp("Opportunity");
//First Query with the opportunity Name provided by user
with(OpptyBC)
{
ClearToQuery();
ActivateField("Name");
SetViewMode(3);
SetSearchSpec("Name",Inputs.GetProperty("OptyName"));
ExecuteQuery(ForwardOnly);
// if record is found inform user that record already exsists
if(FirstRecord())
TheApplication().SetProfileAttr("OptyExsits","Y");
else
{
//Create a NewRecord and set the profile attribute as N
TheApplication().SetProfileAttr("OptyExsits","N");
}
}
}
What I have not provided is the code to create a New Record. But you should be able to figure that out for yourself.
If you think there is better way to achieve this or I have written something wrong ( which I do quite often
) Please let me know. Your valuable comments are always welcome.



(2 votes, average: 3.50 out of 5)



