Do not insert if record allready exists

Vineetha Rohra1
Giga Guru

I have a requirement where i do not want to get a record inserted into a table if it is allready present.

I have a form as follows:

find_real_file.png

For each project code i will have to enter 12 month's amount, meaning For '123' project code i need to enter amount for 123-january upto 123-december.

But i dont want to enter 2 entries for 123-january or any month.

I wrote a business rule for this but it doesn't seem to wotk:

BR:

(function executeRule(current, previous /*null when async*/) {

  var amt = current.amount;

  gs.info(amt);

  var month = current.month;

  // Add your code here

  var gr = new GlideRecord("x_71260_pmo_develo_billing_details");

  //gr.addQuery("project_code", current.project_code);

  //gr.addQuery("project_status", current.project_status);

  //gr.addQuery("year", current.year);

  gr.query();

  if(gr.addQuery("month","==", month))

  {

  gs.info("inside IF");

  gs.info("You have allready entered PO amount for this month for this project.");

  gs.addErrorMessage("You have allready entered PO amount for this month for this project.");

  current.setAbortAction(true);

  }

})(current, previous);

1 ACCEPTED SOLUTION

vipinmathew
Mega Guru

Hi Vineetha,



It's easy to do by code( Business Rule).



var gr = new Gliderecord('your table name');


gr.addQuery('ProjectCode',current.projectcode);


gr.addQuery('ProjectName',current.projectname);


gr.addQuery('Projectstatus',current.projectstatus);


.........................................................................


...............// you can add what ever fields u have unique in field



gr.query();



if(gr.getRowCount() > 0)


{


current.setAbortAction(true);


}



This is generic script ,, modify as u want.



if it is correct answer for you , please mark this answer as CORRECT .




regards,


VIPIN MATHEW


View solution in original post

8 REPLIES 8

ok then you can simply add one more query. if count more than 1 then abort action.


gr.addQuery("month", current.month);



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


vipinmathew
Mega Guru

Hi Vineetha,



It's easy to do by code( Business Rule).



var gr = new Gliderecord('your table name');


gr.addQuery('ProjectCode',current.projectcode);


gr.addQuery('ProjectName',current.projectname);


gr.addQuery('Projectstatus',current.projectstatus);


.........................................................................


...............// you can add what ever fields u have unique in field



gr.query();



if(gr.getRowCount() > 0)


{


current.setAbortAction(true);


}



This is generic script ,, modify as u want.



if it is correct answer for you , please mark this answer as CORRECT .




regards,


VIPIN MATHEW


This worked, thanks for the solution


You are welcome