query with 3 tables (BR)

christiancardos
Kilo Expert

Hello everybody,

I am trying to use now these three tables to perform the following calculations, only clarifying that already worked, but now, due to the fact that i made a many-to-many relationship and add that related list so now you must apply from that table calculations.

I'll explain a little better how it works:

The code makes the value of "u_estimacion_de_hrs", and bring it to the subtract with "u_hrs_disponibles_del_periodo" and put it in the variable "u_hrs_restantes".

find_real_file.png

this is the code:

When to run: After

Insert

Update

condition: estimación de Hrs changes.

This BR is located in the table of incidents

find_real_file.png

Here I have no problem.

--------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------

and now   I have a new related list because I did a new relationship many to many, the idea of having this relation is because i need to have the same incident in different periods.

That relationship was not possible because only he could have an incident at a period.

find_real_file.png

The code should be the value of "u_estimacion_de_hrs", and bring it to the subtract with "u_hrs_disponibles_del_periodo" and put it in the variable "u_hrs_restantes".

Only that now the table is different, the fields that are relational in that list with the exception of the incident number were brought by dot walking.

Could you help me with the BR to work now with this new table, thank you for your help.

Regards,

CC

dvp, I appeal to you, you always have a good answer for this type of unknowns.

I appreciate your help.

thanks for advance.

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Hello Christian,



Write a business rule on m2m table with the below script


find_real_file.png


In this script you need to update the field name on mem table



var prj = new GlideRecord('u_periodo_de_servicio');
prj.addQuery('sys_id', current.YOUR_PERIOD_FIELD_NAME_in_M2M table);
prj.query();


while(prj.next()){
var rp = new GlideRecord('incident');
rp.addQuery('u_periodo', current.YOUR_PERIOD_FIELD_NAME_in_M2M table);
rp.query();
  var count = 0;
while(rp.next()){

  count += rp.u_estimation_de_hrs

}


prj.u_hrs_restantes = prj.u_hrs_disponibles_del_periodo - count;
prj.update();
}


View solution in original post

8 REPLIES 8

hello dvp,


In response to your questions:



the BR is located in table "u_m2m_incidents_periodo_de_s"



The INC 13727 and 13725 both are not   related.



It is important to know that the table "u_m2m_incidents_periodo_de_s" has a many-to-many relationship, I created the table.



Regards


So how are you relating incidents and contracts? Is it through reference field?



On incident table 'u_periodo' field is referenced to which table is it to contract or u_periodo_de_serviceo


 


Hello dvp,


The relationship between incident and contract is with the table "u_m2m_incidents_periodo_de_s".



This is seen in the incident:


find_real_file.png


When I select "new" in the table "u_m2m_incidents_periodo_de_s" in the incident form, the followings appears:


find_real_file.png


-----------------------------------------------------------------------------------------------------------------------------------------------------


On incident table 'u_periodo' field is referenced to which table is it to contract or u_periodo_de_serviceo



I was going through and I just found that the field "u_periodo" does not exist, the relationship between the incident and contract are the table "u_m2m_incidents_periodo_de_s" that has a many-to-many relationship.



Regards,


I hope you can help me.


thanks for advance.


dvp


it's important to mention:



the relationship of the contracts it is also the caller have the company and the company have a contract.



and the relationship between incident and contract is with the table "u_m2m_incidents_periodo_de_s".



I'm trying to solve it but still didn't know why it doesn't work.



could you help me.? Please.


thanks for advance.