Difference between revisions of "General Code"
From iDempiere en
Ngordon7000 (talk | contribs) m (→Chat) |
Ngordon7000 (talk | contribs) (Start a process (or report)) |
||
| Line 62: | Line 62: | ||
} | } | ||
</nowiki> | </nowiki> | ||
| + | |||
| + | = Start a process (or report) = | ||
| + | |||
| + | * Adapted from FinReportJasper | ||
| + | |||
| + | <nowiki>public static void startJavaProcess(Properties ctx, String trxName, | ||
| + | String processId) { | ||
| + | int AD_Process_ID = MProcess.getProcess_ID( | ||
| + | processId, null); | ||
| + | |||
| + | MPInstance instance = new MPInstance(Env.getCtx(), | ||
| + | AD_Process_ID, 0); | ||
| + | instance.saveEx(); | ||
| + | |||
| + | ProcessInfo poInfo = new ProcessInfo( | ||
| + | processId, AD_Process_ID); | ||
| + | poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID()); | ||
| + | // TODO: NCG: correct parameters below | ||
| + | ProcessInfoParameter piOrgId = new ProcessInfoParameter( | ||
| + | "AD_ORG_ID", new BigDecimal(Env.getAD_Org_ID(ctx)), null, | ||
| + | null, null); | ||
| + | ProcessInfoParameter piClientId = new ProcessInfoParameter( | ||
| + | "AD_CLIENT_ID", new BigDecimal(Env.getAD_Client_ID(ctx)), | ||
| + | null, null, null); | ||
| + | ProcessInfoParameter piInvoiceId = new ProcessInfoParameter( | ||
| + | "RECORD_ID", 0, null, null, null); | ||
| + | ProcessInfoParameter[] piParameters = new ProcessInfoParameter[] { | ||
| + | piClientId, piOrgId, piInvoiceId }; | ||
| + | poInfo.setParameter(piParameters); | ||
| + | poInfo.setRecord_ID( 111 ); | ||
| + | |||
| + | // need to commit in order to allow jasper to view the data | ||
| + | Trx trx = Trx.get(trxName, true); | ||
| + | // Rather let the calling process commit | ||
| + | //trx.commit(); | ||
| + | |||
| + | ProcessUtil.startJavaProcess(ctx, poInfo, trx); | ||
| + | }</nowiki> | ||
= Credits = | = Credits = | ||
Revision as of 15:31, 20 August 2015
Chat
Quickly add a chat to a PO record.
package za.co.ntier.common;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MChat;
import org.compiere.model.MChatEntry;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
/**
* @author nTier Software Services ngordon7000
* Date: 29 Jun 2015
* Description: Chat support
*/
public class NTierChatUtils {
/** Logger */
private static CLogger log = CLogger.getCLogger(NTierChatUtils.class);
/**
*/
public static MChat getChat(Properties ctx, String trxName,
PO po) {
final String whereClause = "AD_Client_ID=? and AD_Table_ID=? AND Record_ID=? ";
MChat retValue = new Query(ctx, MChat.Table_Name, whereClause,
trxName).setParameters(Env.getAD_Client_ID(ctx), po.get_Table_ID(), po.get_ID())
.firstOnly();
return retValue;
}
/**
* Add chat
*/
public static void addChat(Properties ctx, String trxName,
PO po, String comments) {
try {
String descr = "";
descr = comments;
descr = NTierStringUtils.left(descr, 255);
MChat chat = getChat(ctx, trxName, po);
if (chat == null) {
chat = new MChat (ctx, po.get_Table_ID(), po.get_ID(), descr, trxName);
chat.saveEx(trxName);
}
log.info(String.format("Chat - %s - '%s'", po.get_TableName(), descr));
MChatEntry chatEntry = new MChatEntry(chat, descr);
chatEntry.saveEx(trxName);
} catch (Exception e) {
log.log(Level.SEVERE, "^^^", e);
log.info(String.format("^^^ Failed to save chat record"));
}
}
}
Start a process (or report)
- Adapted from FinReportJasper
public static void startJavaProcess(Properties ctx, String trxName,
String processId) {
int AD_Process_ID = MProcess.getProcess_ID(
processId, null);
MPInstance instance = new MPInstance(Env.getCtx(),
AD_Process_ID, 0);
instance.saveEx();
ProcessInfo poInfo = new ProcessInfo(
processId, AD_Process_ID);
poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// TODO: NCG: correct parameters below
ProcessInfoParameter piOrgId = new ProcessInfoParameter(
"AD_ORG_ID", new BigDecimal(Env.getAD_Org_ID(ctx)), null,
null, null);
ProcessInfoParameter piClientId = new ProcessInfoParameter(
"AD_CLIENT_ID", new BigDecimal(Env.getAD_Client_ID(ctx)),
null, null, null);
ProcessInfoParameter piInvoiceId = new ProcessInfoParameter(
"RECORD_ID", 0, null, null, null);
ProcessInfoParameter[] piParameters = new ProcessInfoParameter[] {
piClientId, piOrgId, piInvoiceId };
poInfo.setParameter(piParameters);
poInfo.setRecord_ID( 111 );
// need to commit in order to allow jasper to view the data
Trx trx = Trx.get(trxName, true);
// Rather let the calling process commit
//trx.commit();
ProcessUtil.startJavaProcess(ctx, poInfo, trx);
}
Credits
Initial contribution by: nTier Software Services http://www.ntier.co.za ngordon7000
Add your credit here.
