Scheduled execution of a custom script

  • 23 November 2020
  • 15 replies
  • 2055 views

Userlevel 7
Badge +20
  • Superhero (Partner)
  • 663 replies

There were several posts regarding the requirement of schedule execution of a custom script in IFS. There could be several ways of doing this and this topic explains how to build a common solution using Events and Scheduled Tasks.

IFS has two event types, Application Defined and Custom defined. Custom defined events are based on triggers and can be created from IFS Solution Manager. Application defined events are created via script and the triggering of the event is done inside the PLSQL logic. 

 

Step1: Create Application Defined Event and action

Deploy following code in database using AppOwner. Check the attachment for detailed script.

BEGIN
Event_SYS.Enable_Event('Event', 'C_SEND_DOC_REV',
'Send Document revision',
'DUMMY/STRING^');
END;

 

Navigate to the Events and search for the event ID.

 

RMB on the event,  Create new action

Choose the Action Type SQL and write your code to execute on a schedule.

 

 

Step 2: Create the Scheduled Task

Navigate to New Database Task window and create a new database task for Event_Sys.Event_Execute method, Save

 

Create a new Scheduled task. Fill the event LU and event ID which is we created in step 1. Schedule it as per your requirement.

 

That's basically all you need to schedule your custom script!

 

👍 this topic if you think it’s useful and comment any other ‘hacks’ or suggestions.

 

Cheers!


This topic has been closed for comments

15 replies

Userlevel 4
Badge +7

Hello,

EVENT_SYS.EVENT_EXECUTE method is no longer accessible in "New Database Task Schedule" form in 21R1 and R2, even with IFSAPP. It was very useful to schedule an event action without triggering the action itself. Today, combined with the bpa, it could make all the difference.

Does anyone know of a way to retrieve it or an alternative ?

Badge +1

An other option is using EVENT_DATA_ (with a little trick)

You can use LF (character number 10 in the ASCII charset) - You will need a special editor to do that Notepad++ , UltraEdit, …

Ex:

$NEW:CATALOG_NO=123456

$NEW:CONTRACT=Test

You need a LF after each of the parameters like this:

$NEW:CATALOG_NO=123456<LF>$NEW:CONTRACT=Test<LF>

Userlevel 7
Badge +20

OK, but could you somehow create the event in a way where that is possible?

 

You just need to create the event with the parameters needed.

Below event is created with two attributes (contract and wo_no)

BEGIN
Event_SYS.Enable_Event('Event', 'TEST_EVENT',
'Test Event',
'CONTRACT/STRING^WO_NO/NUMBER^');
END;

 

They will appear in the event action and you can use them as usual.

 

How to assign values to the event attributes and execute the event

You need to create a IFS message, pack the attribute values and call the event.

DECLARE
event_enabled_ BOOLEAN := Event_SYS.Event_Enabled('Event','TEST_EVENT');
event_msg_ VARCHAR2(32000);

BEGIN
IF event_enabled_ THEN

event_msg_ := Message_SYS.Construct('TEST_EVENT');
Message_SYS.Add_Attribute(event_msg_,'CONTRACT','01'); --contract
Message_SYS.Add_Attribute(event_msg_,'WO_NO','77568'); --wo no

event_sys.event_execute(event_lu_name_ => 'Event',
event_id_ => 'TEST_EVENT',
event_data_ => event_msg_);

END IF;
END;

 

Hope it helps!

Damith

 

Userlevel 3
Badge +8

OK, but could you somehow create the event in a way where that is possible?

Userlevel 7
Badge +20

Could you please explain how I could access the EVENT_DATA_ in my pl/sql event action ?

That would be very helpful.

BR Kresten

 

Hi Kresten,

 

EVENT_DATA_ is a IFS Message which constructed using Message_Sys. When executing events, it packs the values for event attributes and call the event. But in this case we can’t add the event_data_ since it has a special format and  sparerate with new lines so it’s not possible to add it in the Task Schedule window.

Hope it helps!

Damith

Userlevel 3
Badge +8

Could you please explain how I could access the EVENT_DATA_ in my pl/sql event action ?

That would be very helpful.

BR Kresten

Badge +3

Solved my own problem! 

In case anyone else has issues, when you click “Select Method”, it’s here:

IFS Base Functionality > Event > EVENT_SYS

Badge +3

My only problem is that when I set up the Scheduled Task,  I can’t find the EVENT_SYS.EVENT_EXECUTE when I browse the methods. I’m talking about Apps9. Where is it?? Help! Thanks!

Userlevel 2
Badge +6

Hi @oguz

 

I’d like to send it but I havent have it yet  :( I’ll work on it 

 

Hi @Amy and @0guz ,

 

I’ve had the similar requirement to mail several document revisions in a mail and luckily for you, I have a blog post explaining the steps :sunglasses:

You could use the same steps in the below blog with modifications to the cursor to fetch the document

https://dsj23.me/2017/03/20/include-additional-attachments-in-ifs-e-mail-report/

 

Hope you could make it work.

Cheers!

Damith

 

 

Thank you very much!

Userlevel 7
Badge +20

Hi @oguz

 

I’d like to send it but I havent have it yet  :( I’ll work on it 

 

Hi @Amy and @0guz ,

 

I’ve had the similar requirement to mail several document revisions in a mail and luckily for you, I have a blog post explaining the steps :sunglasses:

You could use the same steps in the below blog with modifications to the cursor to fetch the document

https://dsj23.me/2017/03/20/include-additional-attachments-in-ifs-e-mail-report/

 

Hope you could make it work.

Cheers!

Damith

Userlevel 2
Badge +6

Hi @oguz

 

I’d like to send it but I havent have it yet  :( I’ll work on it 

Userlevel 4
Badge +10

@dsj It is amazing trick i think! Thank you so much.

@Amy i want to see your pl SQL block for sent to mail with documents with script, Can you share with me?

Userlevel 7
Badge +20

 Hi @dsj 

Thank you! But it didnt get one thing. Is this work for all doc revision ? I mean how can  I sent the document that I want to send via e mail for using your solution? Where should I select it?

Hi Amy,

This post explains more of a general way of executing some action on a scheduled. You can write the pl/sql code in the event action to select the document(s) and send via mail :)

 

Regards,

Damith

 

 

 

Userlevel 2
Badge +6

 Hi @dsj 

Thank you! But it didnt get one thing. Is this work for all doc revision ? I mean how can  I sent the document that I want to send via e mail for using your solution? Where should I select it?

Userlevel 5
Badge +11

If only I’d know this a year ago! :sob:

Thanks @dsj.