I want to update opportunity stage value when save button clicked.
opportunity stage is a dropdown field in opportunity module. In that dropdown field contains : Lead, new business opportunity, device considered, sample requested, design in and design win.
So for this I’ve created workflows like this:
1st Workflow:
Condition:
when opportunity stage Equals To Value Lead
Action:
modify record Opportunity stage Equals To Value New Business Opportunity
2nd Workflow:
Condition:
when opportunity stage Equals To Value New Business Opportunity
Action:
modify record Opportunity stage Equals To Value Device Considered
3rd Workflow:
Condition:
when opportunity stage Equals To Value Device Considred
Action:
modify record Opportunity stage Equals To Value Sample Requested
After Creating all workflows, I created new opportunity when save button clicked All Workflows execute at a time and then opportunity stage value directly goes to Device Considered and sometimes it goes to Last stage.
Please help me how do I change stage one by one when button clicked…
I think that you are better off using an after_save logic hook or else you have to introduce some kind of flag to avoid having all workflows run at once.
Try saving the bean when you have modified it. Note that this is an after_save so the record has already been saved and in order to maintain your changes you also should save.
Otherwise:
Use a before_save (sorry if I suggested after_save) and you don’t need to save the bean because it is going to be saved in the next phases of the flow execution. If you use a before_save, be careful because you may end up with two copies of the same record if you save the bean
While testing you could try putting some echo statements followed by exit; to test if you are getting in the portion of code and if the values are being modified. Once finished your test you should remove these statements.
Final note:
You should be aware that each time a record is modified the stage will advance to the next one (for example a user edits a record and he immediately realises that he typed a wrong telephone number (or whatever), so if he edits again the record, the stage is modified again).
I think that you should improve the logic for this reason.
In this way you can see wheter a value is being assigned. Once you have checked it remove the echo and exit statements.
Then, at the end of your script you have to save the bean.
Instead of nested if statements I would use a switch statement to make sure that you control all the possible values.
One more thing:
You have to assign the key of the dropdown value. Not the Label.
If you assign the label you may get unpredictable results.
If you don’t know the keys you can check them either in Admin->Dropdown Editor and click on your dropdown or open the file custom/include/language/en_us.lang.php (or the language you are using)
without $bean->save also it’s working…
there is no problem with $bean->save
Can we call logic hooks with any other custom buttons…?
I create one button in opportunity edit view.
when i click that button logic hook particular logic hook function should call.
is it possible…
You will need to create a controller.php file in the custom/modules/Opportunities folder.
<?php
class OpportunitiesController extends SugarController {
//Can now put actions here
public function action_NameHere(){
//do stuff here
echo "Hello world!";
die();
}
}
You can then call with jquery ajax:
Something like this:
$.ajax({
url: "index.php?module=Opportunities&action=NameHere",
})
.done(function( result ) {
alert(result);
});