Error when trying to trigger new program rules via API

I’ve added a new data element and program rule to populate that data element to a program stage. I’m trying to use the tracker API to update the values of this data element for existing events, as described here and here.

When I do this, I get a E1307 error. Unable to assign value to data element. The provided value must be empty or match the calculated value 3

However, in the payload the data element is empty, so its not clear why I am getting this error. I can also go to the event that I’m trying to update in tracker capture, and the program rules trigger appropriately, so it is not a program rule issue. I seem to be able to update the values with program rules just fine when a value already exists for the data element, but I can’t do anything if no value exists.

I’m on 2.39

Any help would be appreciated.

It appears you’re trying to assign a value to a data element that has a calculated value, and the provided value doesn’t align with the calculated value. This error typically arises when attempting to manually update the value of a data element controlled by a program rule or calculation. You can try to initialize the data element with some default value, then update it. Also just check if you are using the correct endpoint.

Maybe you can also check what the logs are picking up and share for other to help, also check if you have other program rules that might prevent manual updating of the new data element.

1 Like

Hi @WaluQ,
Thanks for the response. It seems to be a conflicting program rules issue… when entering data via the interface, the value of the data element is determined based on the order the program rules are triggered, but it seems like the priority is not working via the api.

1 Like

Hi @kstankevitz

So if I understand correctly, there is a program rule that sets the initial value and then it is followed by other program rules? When trying to trigger the program rule via the API, you’re not triggering the one that sets the initial value?

Could you give more details about the program rules you created? Thanks!

Hi @Gassim ,
In simple terms, I have a data element for status, and I have three program rules, one to set it to status 1, one to set it to status 2, and one to set it to status 3. I’m not exactly sure what is happening. I’m following the instructions of this thread: How to trigger program rules on a list of event - #8 by rithvik

about how to trigger program rules for events. I’m doing those steps almost exactly, but the program rules don’t seem to be assigning a status to the data element.

1 Like

Hi @kstankevitz

I’d be very helpful if I can reproduce this to try and figure out what is happening.

Let’s start with the first program rule:

  1. An API request is sent to trigger this program rule
    a. what is the request/response please?
  2. The program rule is supposed to be triggered based on a program rule expression:
    b. what is the expression please?
  3. The program rule’s action as we already know is setting a certain data element with status:
    c. what is the data type of this data element?

Thank you!

Hi @Gassim -
Here is an example in the play site. This is following the instructions @rithvik provided here:

  1. Import this metadata. This imports a new data element and two program rules:
    dataElements (19).json (9.6 KB)
  2. Open the Child Program and the Birth Program Stage, and add “test data element” to the Birth program stage. Save the program.
  3. Open tracker capture and an existing event to confirm the program rule is working (example here: DHIS 2 Demo - Sierra Leone)
  4. Now, I’m trying to trigger this rule for previous events, as described in the two links in my first post. Here are those instructions again:
  5. Download this payload. DHIS 2 Demo - Sierra Leone Note this person has no value for the data element we added (GjVkPStfzJB) but the program rule should trigger and change the value to true.
  6. in your downloaded file, change instances to events and save
  7. make the following POST request to import the events.
    with the exported events as payload.
  8. You would expect the program rule to trigger and update the value for the data element we added (GjVkPStfzJB), but it doesn’t/.
1 Like