Skip to main content

Hello,

 

I would like to automatically close a Business Opportunity when it expires (expiration date = today’s date). I wanted to do this via a Workflow, but sadly, you can’t schedule workflows to run daily, they have to be based off of a projection action or event action. 

I looked at scheduled database tasks, and I found the method Set_Closed for Business Opportunities, but sadly, the scheduled database task I set is not working. I have this set up so far:

I added the “Expiration_date” parameter. 

Whenever this is run, I get this error: “ORA-20115: BusinessOpportunity.The "Business Opportunity" has already been removed by another user.”

and no Business Opportunities close. Am I missing something? I’ve worked with some scheduled database tasks before that automatically create pick lists and reserve customer order items, but this is the first time I’ve seen parameters that (I’m assuming) are passed into the API to set the BO as either Won or Lost. 

The API Explorer documentation for this method didn’t help.

Can anyone provide any insight? I’d really appreciate it.

 

Thanks,
Bryan     

Just to add to this, I have a workflow that automatically calculates the expiration date for the BO so these values are getting populated.


One finding: When there is no value for sysdate, the error goes away, but I’d like this to only run for BO’s that are expired. Also, how do I know this scheduled database task is running on all BO’s? I’d like it to run on all of them that have that expiration date, but from the error log, it looks like this is running just for one BO.

Do I need to create a task to grab all of the expired items and then chain that task with this one? I’m not sure how IFS works in the back-end and there doesn’t seem to be any documentation on this or “best practice” when building these.

Thanks,
Bryan


HI @bdoucette , 

Possibly an option would be to create a new oracle procedure in the back end (if you can do a CRIM/MOD) where it selects all expired BOs and then call Set_Closed() for each record. And after that you can create a new schedule database task for this new method (ex: for following Close_Expired_Opportunities method) to run every day.

 

Following is just an example. I haven’t fully tested this.

Also there are validation checks before closing the opportunity and you can get errors from business logic if everything is not satisfied (Same validations as when closing the Business Opportunity from the client). Ex: If you have setup CRM access then there is a possibility to get access errors if the user who runs the schedule task doesn’t have access to opportunity records.

 

PROCEDURE Close_Expired_Opportunities
IS
   CURSOR get_expired_opportunities IS 
      SELECT opportunity_no
      FROM business_opportunity_tab 
      WHERE trunc(expiration_date) >= trunc(sysdate)
      AND rowstate != 'Closed';    
BEGIN
   FOR rec_ IN get_expired_opportunities LOOP
      Set_Closed(rec_.opportunity_no, LOST_WON_API.DB_LOST, '40', '330', 'Business Opportunity Expired');           
   END LOOP; 
END Close_Expired_Opportunities;

 

Best regards,

Masheesh


Hi @Masheesh 

I appreciate the quick response!

When you mention back-end, do you mean something developed using Developer Studio? Sadly I do not have any experience with that. Is that difficult to learn? I plan on taking an IFS Cloud Development course relatively soon. That script you wrote seems very helpful though, I wish creating IFS procedures and functions was easier to do without having to access the backend.

Thanks,
Bryan


HI Bryan,

 

Yes, you have to use developer studio to add this kind of a function in Business_Opportunity_API. (You have to follow some standards here since it will be a CRIM).

I will also check with experts about workflow or any other alternative ways to achieve this type of a scenario. So you can avoid suggested customizations in the back end if there is another way (not sure though).

Mean time I will check with our R&D team whether there is a possibility/need to give this type of a back end function to close opportunities in a future core release. 

Best regards,

Masheesh


Hi @Masheesh 

I see, well thank you so much, I really appreciate it! I was looking into either chaining schedule database tasks together, one to fetch all expired BO’s and another to close them, but sadly there doesn’t seem to be a database task that fetches multiple BO’s. 

I was also thinking of doing a workflow, but getting it to trigger daily is a bit tricky. Is there no way to trigger a workflow daily? If not I’m going to have to piggyback off of a daily scheduled database task, but so far, I don’t think I’ve found a good one.

Thanks again, I appreciate your help a ton!
Bryan


Hi @Masheesh 

Thanks again for the answer yesterday, I really appreciate it. I’m curious though, where would you add that in developer studio? I’ve been trying to get into it. I’m taking two of the paid IFS Academy courses on it soon, and I’m interested where you add that to the BO API. 
Thanks again, I appreciate it as you’re one of the only users that has been responding lately.
Bryan


HI @bdoucette ,

Sorry for the late reply. Hope you managed to handle this. Just a comment about this customization, better if you can contact IFS consulting about this. Otherwise your changes will be removed with next update/upgrade. So basically we don’t directly add functions and deploy the API when do customizations (for testing purposes this would be fine).

So good to follow the correct processes when you do customizations with the help of consulting.

Best regards,

Masheesh


Reply