Inserting new Activity for Case Screen by code - acumatica

I am trying to insert a new Activity for Case. The code which I have written executes without any error but it even does not inserts any Activity. Let me know if I am missing anything.
Here is the code
CRActivity actiCloud9 = new CRActivity();
actiCloud9.Type = "N"; // Note
actiCloud9.Subject = current.Summary;
actiCloud9.Body = current.Description;
actiCloud9.UIStatus = current.Status;
actiCloud9.StartDate = current.StartDate;
actiCloud9.IsPrivate = true; // current.IsInternal;
actiCloud9.RefNoteID = Base.CaseCurrent.Current.NoteID;
Base.Activities.Cache.Insert(actiCloud9);

Try this.
[PXOverride]
public void Persist(Action del)
{
if ((Base.Case.Cache.GetStatus(Base.Case.Current) == PXEntryStatus.Inserted || Base.Case.Cache.GetStatus(Base.Case.Current) == PXEntryStatus.Updated))
{
CRActivityMaint objGraph = PXGraph.CreateInstance<CRActivityMaint>();
CRActivity actiCloud9 = new CRActivity();
actiCloud9.Type = "N"; // Note
actiCloud9.Subject = "Subject";
actiCloud9.Body = "Body";
actiCloud9.RefNoteID = Base.CaseCurrent.Current.NoteID;
objGraph.Activities.Cache.Insert(actiCloud9);
objGraph.Actions.PressSave();
}
del();
}

Related

Add an additional line on the grid

I am looking for help, I hope I can solve this problem.
I've created a new screen and I'm filtering all the Revalue Accounts information.
With this screen, what I want to do is insert and at the same time add an additional new line within the grid.
Here is my new created screen and the button that inserts GLTran
I am attaching an image where I want the line to be added at insert time
Here I share code that I have and it does not work for the additional line.
private void CreateDNGL(Batch batch)
{
var graph = PXGraph.CreateInstance<JournalEntry>();
if (graph.BatchModule.Current == null)
{
Batch cmbatch = new Batch();
cmbatch.BranchID = batch.BranchID;
cmbatch.Module = batch.Module;
cmbatch.Status = "U";
cmbatch.AutoReverse = true;
cmbatch.Released = true;
cmbatch.Hold = false;
cmbatch.CuryDebitTotal = batch.CuryDebitTotal;
cmbatch.CuryCreditTotal = batch.CuryCreditTotal;
cmbatch.FinPeriodID = batch.FinPeriodID;
cmbatch.CuryID = batch.CuryID;
cmbatch.CuryInfoID = batch.CuryInfoID;
cmbatch.DebitTotal = batch.DebitTotal;
cmbatch.CreditTotal = batch.CreditTotal;
cmbatch.Description = "Head new insert";
cmbatch = graph.BatchModule.Insert(cmbatch);
}
foreach (GLTran item in PXSelect<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(this, batch.Module, batch.BatchNbr))
{
GLTran tran = new GLTran();
tran.SummPost = item.SummPost;
tran.ZeroPost = false;
tran.DebitAmt = item.DebitAmt;
tran.CreditAmt = item.CreditAmt;
tran.CuryDebitAmt = item.CuryDebitAmt;
tran.CuryCreditAmt = item.CuryCreditAmt;
tran.AccountID = item.AccountID;
tran.SubID = item.SubID;
tran.LineNbr = item.LineNbr;
tran.LedgerID = item.LedgerID;
tran.TranType = item.TranType;
tran.TranClass = item.TranClass;
tran.RefNbr = string.Empty;
tran.FinPeriodID = item.FinPeriodID;
tran.TranDesc = "Test detail";
tran.Released = true;
tran.ReferenceID = item.ReferenceID;
tran = graph.GLTranModuleBatNbr.Insert(tran);
Account account = PXSelect<Account, Where<Account.accountID,
Equal<Required<Account.accountID>>>>.Select(graph, item.AccountID);
xLocEquivalAcct equivalAcct = PXSelect<xLocEquivalAcct, Where<xLocEquivalAcct.acctCD,
Equal<Required<xLocEquivalAcct.acctCD>>>>.Select(graph, account.AccountCD);
if (equivalAcct != null)
{
/*here is added for an additional line*/
var glTran = graph.GLTranModuleBatNbr.Insert();
graph.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, 343567);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, 281);
glTran.TranDesc = "add extra line";
if (item.DebitAmt != 0m && item.CreditAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyDebitAmt>(glTran, item.CuryDebitAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.debitAmt>(glTran, item.DebitAmt);
}
}
if (item.CreditAmt != 0m && item.DebitAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyCreditAmt>(glTran, item.CuryCreditAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.creditAmt>(glTran, item.CreditAmt);
}
}
glTran = graph.GLTranModuleBatNbr.Update(glTran);
}
}
graph.Save.Press();
}
I hope I was clear with my question.
This code will create a copy of the originating batch and insert additional lines.
#Warning Your original code was attempting to create a batch that was already released but unposted. I can update my answer to match your requirement but this will break Acumatica work-flow.
Please find code example below :
public class JournalEntryExtension : PXGraphExtension<JournalEntry>
{
public PXAction<Batch> CopyCreate;
//CommitChanges being set to false allows the graph to not be considered dirty when there are errors that we manually show on screen. Case #207998
[PXButton(CommitChanges = false)]
[PXUIField(DisplayName = "Copy Create", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true)]
protected virtual IEnumerable copyCreate(PXAdapter pxAdapter)
{
if (Base.BatchModule.Current != null)
{
if (Base.IsDirty)
{
Base.BatchModule.Ask("You must discard your unsaved changes to be able to press this button.", MessageButtons.OK);
}
else
{
Batch batch = Base.BatchModule.Current;
PXLongOperation.StartOperation(this, () => CreateDNGL(batch));
}
}
return pxAdapter.Get();
}
private static void CreateDNGL(Batch batch)
{
JournalEntry graph = PXGraph.CreateInstance<JournalEntry>();
Batch newBatch = PXCache<Batch>.CreateCopy(batch);
newBatch.NoteID = null;
newBatch.Description = "Test header";
newBatch = graph.BatchModule.Insert(newBatch);
GLTran newTran;
foreach (GLTran tran in PXSelectReadonly<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(graph, batch.Module, batch.BatchNbr))
{
newTran = PXCache<GLTran>.CreateCopy(tran);
newTran.Module = null;
newTran.BatchNbr = null;
newTran.NoteID = null;
newTran.TranDesc = "Test detail";
newTran = graph.GLTranModuleBatNbr.Insert(newTran);
}
if (true)
{
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryDebitAmt = 1000;
newTran.TranDesc = "Additional Line 1";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryCreditAmt = 1000;
newTran.TranDesc = "Additional Line 2";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
}
graph.Save.Press();
}
}
Original Batch :
New Batch :

How to create a custom Order Type using customization plug-in (Acumatica)

How to create a custom Order Type using customization plug-in? I used a manual from here. I tried to initialize required filds from exesting order type, but without success. I tried to use Update method on graph as well. Every time I get a common error: Inserting 'Order Type' record raised at least one error. Please review the errors.' and can't see what field the issue is related to. My UpdateDatabase() method:
public override void UpdateDatabase()
{
SOOrderTypeMaint orderTypeGraph = PXGraph.CreateInstance<SOOrderTypeMaint>();
string newOrderTypeName = "SR";
var existingOrderType = orderTypeGraph.soordertype.Search<SOOrderType.orderType>(newOrderTypeName);
if (existingOrderType.Count != 0)
{
WriteLog(string.Format("{0} type already exist", newOrderTypeName));
}
else
{
SOOrderType exempleOrderType = SOOrderType.PK.Find(orderTypeGraph, "SO");
SOOrderTypeOperation exgrid = SOOrderTypeOperation.PK.Find(orderTypeGraph, "SO", "I");
var ourGrid = new SOOrderTypeOperation();
var sROrderType = new SOOrderType();
ourGrid.Operation = exgrid.Operation;
ourGrid.INDocType = exgrid.INDocType;
ourGrid.OrderPlanType = exgrid.OrderPlanType;
ourGrid.ShipmentPlanType = exgrid.ShipmentPlanType;
ourGrid.RequireReasonCode = exgrid.RequireReasonCode;
sROrderType.OrderType = newOrderTypeName;
sROrderType.Descr = "description";
sROrderType.Active = exempleOrderType.Active;
sROrderType.OrderNumberingID = exempleOrderType.OrderNumberingID;
sROrderType.FreightSubID = exempleOrderType.FreightSubID;
sROrderType.DiscountAcctID = exempleOrderType.DiscountAcctID;
sROrderType.DiscountSubID = exempleOrderType.DiscountSubID;
sROrderType.Behavior = exempleOrderType.Behavior;
sROrderType.DefaultOperation = exempleOrderType.DefaultOperation;
sROrderType.ARDocType = exempleOrderType.ARDocType;
sROrderType.AllowQuickProcess = exempleOrderType.AllowQuickProcess;
sROrderType.DiscSubMask = exempleOrderType.DiscSubMask;
sROrderType.CalculateFreight = exempleOrderType.CalculateFreight;
sROrderType.SalesSubMask = exempleOrderType.SalesSubMask;
sROrderType.FreightSubMask = exempleOrderType.FreightSubMask;
sROrderType.FreightAcctID = exempleOrderType.FreightAcctID;
sROrderType.InvoiceNumberingID = exempleOrderType.InvoiceNumberingID;
sROrderType.RequireShipping = exempleOrderType.RequireShipping;
orderTypeGraph.soordertype.Insert(sROrderType);
orderTypeGraph.operations.Insert(ourGrid);
orderTypeGraph.soordertype.Update(sROrderType);
orderTypeGraph.operations.Update(ourGrid);
orderTypeGraph.Save.Press();
WriteLog(string.Format("{0} type has been added", newOrderTypeName));
}
}
Acumatica trace:
8/6/2021 6:27:14 PM Error:
Publishing of a customization project failed with an error CustomizationProjects:TestAssignment2
PX.Data.PXOuterException: Error: Inserting 'Order Type' record raised at least one error. Please review the errors.
at PX.Data.PXUIFieldAttribute.CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
at PX.Data.PXCache.OnCommandPreparing(String name, Object row, Object value, PXDBOperation operation, Type table, FieldDescription& description)
at PX.Data.PXCache`1.PersistInserted(Object row, Boolean bypassInterceptor)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
at PX.Data.PXGraph.Persist(Type cacheType, PXDBOperation operation)
at PX.Data.PXGraph.Persist()
at PX.Data.PXSave`1.d__2.MoveNext()
at PX.Data.PXAction`1.d__33.MoveNext()
at PX.Data.PXAction`1.d__33.MoveNext()
at PX.Data.PXAction`1.PressImpl(Boolean internalCall, Boolean externalCall)
at PX.Data.PXAction`1.Press()
at TestAssignment2.ServiceRepairCreator.UpdateDatabase() in D:\AcumaticaFolder\TestAssignment\App_Data\Projects\TestAssignment2\TestAssignment2\ServiceRepairCreator.cs:line 58
at Customization.CstWebsiteStorage.UpdateDatabaseFromPlugin(CustomizationPlugin plugin, PXPublishOptions options)
at Customization.CstWebsiteStorage.RunPluginsDbUpdate()
at PX.Web.Customization.Controls.Publish.RunPlugins(HttpResponse response)
The problem was in mandatory fields. This method works when u need to create a new order type. Thanks, everyone, for your help.
public override void UpdateDatabase()
{
SOOrderTypeMaint graph = PXGraph.CreateInstance<SOOrderTypeMaint>();
string newOrderTypeName = Constants.serviceRepairOrderType;
var existingOrderType = graph.soordertype.Search<SOOrderType.orderType>(newOrderTypeName);
if (existingOrderType.Count != 0)
{
WriteLog(string.Format("{0} type already exist", newOrderTypeName));
}
else
{
SOOrderType exempleOrderType = SOOrderType.PK.Find(graph, SOOrderTypeConstants.SalesOrder);
var soSRTypeGeneral = graph.soordertype.Insert();
soSRTypeGeneral.OrderType = newOrderTypeName;
soSRTypeGeneral.Descr = "description";
soSRTypeGeneral.Template = exempleOrderType.Template;
soSRTypeGeneral.Behavior = exempleOrderType.Behavior;
soSRTypeGeneral.ARDocType = exempleOrderType.ARDocType;
soSRTypeGeneral.INDocType = exempleOrderType.INDocType;
soSRTypeGeneral.FreightSubID = exempleOrderType.FreightSubID;
soSRTypeGeneral.OrderPlanType = exempleOrderType.OrderPlanType;
soSRTypeGeneral.DiscountSubID = exempleOrderType.DiscountSubID;
soSRTypeGeneral.FreightAcctID = exempleOrderType.FreightAcctID;
soSRTypeGeneral.DiscountAcctID = exempleOrderType.DiscountAcctID;
soSRTypeGeneral.ShipmentPlanType = exempleOrderType.ShipmentPlanType;
soSRTypeGeneral.OrderNumberingID = exempleOrderType.OrderNumberingID;
soSRTypeGeneral.DefaultOperation = exempleOrderType.DefaultOperation;
soSRTypeGeneral.DaysToKeep = exempleOrderType.DaysToKeep;
soSRTypeGeneral.COGSSubMask = exempleOrderType.COGSSubMask;
soSRTypeGeneral.DiscSubMask = exempleOrderType.DiscSubMask;
soSRTypeGeneral.OrderPriority = exempleOrderType.OrderPriority;
soSRTypeGeneral.FreightSubMask = exempleOrderType.FreightSubMask;
soSRTypeGeneral.RequireShipping = exempleOrderType.RequireShipping;
soSRTypeGeneral.DiscAcctDefault = exempleOrderType.DiscAcctDefault;
soSRTypeGeneral.COGSAcctDefault = exempleOrderType.COGSAcctDefault;
soSRTypeGeneral.SupportsApproval = exempleOrderType.SupportsApproval;
soSRTypeGeneral.AllowQuickProcess = exempleOrderType.AllowQuickProcess;
soSRTypeGeneral.FreightAcctDefault = exempleOrderType.FreightAcctDefault;
var soSRTypeTemplate = graph.operations.Insert();
soSRTypeTemplate.OrderType = soSRTypeGeneral.OrderType;
soSRTypeTemplate.Active = true;
soSRTypeTemplate.InvtMult = -1;
soSRTypeTemplate.Operation = "I";
soSRTypeTemplate.INDocType = "INV";
soSRTypeTemplate.OrderPlanType = "60";
soSRTypeTemplate.ShipmentPlanType = "61";
var soSRTypeQuickParam = graph.quickProcessPreset.Insert();
soSRTypeQuickParam.OrderType = soSRTypeGeneral.OrderType;
soSRTypeQuickParam.UpdateIN = true;
soSRTypeQuickParam.CreateShipment = true;
soSRTypeQuickParam.PrepareInvoice = true;
soSRTypeQuickParam.ConfirmShipment = true;
graph.Persist();
WriteLog(string.Format("{0} type has been added", newOrderTypeName));
}
}

Changes in cache saved in database before calling Persist()

I have created a new grid with Case classes in Contract Template screen which updates case classes for particular Contract Template. There is a checkbox for every case class in the grid and when I check/Uncheck, RowUpdatedEventHandler is triggered and I am updating the contents of Cache.
I have overridden Persist() to save the contents of the cache in Database. But before Persist() is being called the changes are saved in the database and the cache is cleared.Please, Someone help me with this
protected void CRCaseClass_RowUpdated(PXCache sender, PXRowUpdatedEventArgs
e)
{
CRCaseClass newrow = (CRCaseClass)e.Row;
CRCaseClass oldrow = (CRCaseClass)e.OldRow;
ContractTemplate row = contracts.Current;
CaseContract c = new CaseContract();
CRCaseClassExt newrow_ext =
PXCache<CRCaseClass>.GetExtension<CRCaseClassExt>(newrow);
CRCaseClassExt oldrow_ext =
PXCache<CRCaseClass>.GetExtension<CRCaseClassExt>(oldrow);
c.CaseClassID = newrow.CaseClassID;
c.ContractID = row.ContractID;
c.Active = newrow_ext.Check.Value;
caseContract.Insert(c);
}
[PXOverride]
public void Persist()
{
bool c = caseContract.Cache.IsInsertedUpdatedDeleted;
CaseContract cc = null;
IEnumerable cacheRecords = caseContract.Cache.Inserted;
List<CaseContract> recordsToBePersisted = new List<CaseContract>();
ContractTemplate row = contracts.Current;
foreach (CaseContract cr in cacheRecords)
{
PXResultset<CaseContract> v = PXSelect<CaseContract, Where<CaseContract.contractID,
Equal<Required<ContractTemplate.contractID>>, And<CaseContract.caseClassID,
Equal<Required<CRCaseClass.caseClassID>>>>>.Select(Base, row.ContractID, cr.CaseClassID);
if (v.Count != 0 && v.Count == 1)
{
cc = v.GetEnumerator().Current;
cc.Active = cr.Active;
}
else if (v.Count == 0)
{
cc = new CaseContract();
cc.CaseClassID = cr.CaseClassID;
cc.ContractID = cr.ContractID;
cc.Active = cr.Active;
}
else {
//Error Logic
}
recordsToBePersisted.Add(cc);
}
//clean all cache
//insert all values from recordsToBePersisted
caseContract.Cache.Clear();
foreach (CaseContract i in recordsToBePersisted) {
caseContract.Insert(i);
}
Base.Persist();
The Acumatica way to override virtual methods in BLC extensions is slightly different from what you get used to with the .Net framework. Below is the updated version of your code, that should resolve the issue with empty caches. For more details on this topic, please refer to the Acumatica Customization Guide
[PXOverride]
public void Persist(Action del)
{
bool c = caseContract.Cache.IsInsertedUpdatedDeleted;
CaseContract cc = null;
IEnumerable cacheRecords = caseContract.Cache.Inserted;
List<CaseContract> recordsToBePersisted = new List<CaseContract>();
ContractTemplate row = contracts.Current;
foreach (CaseContract cr in cacheRecords)
{
PXResultset<CaseContract> v = PXSelect<CaseContract, Where<CaseContract.contractID,
Equal<Required<ContractTemplate.contractID>>, And<CaseContract.caseClassID,
Equal<Required<CRCaseClass.caseClassID>>>>>.Select(Base, row.ContractID, cr.CaseClassID);
if (v.Count != 0 && v.Count == 1)
{
cc = v.GetEnumerator().Current;
cc.Active = cr.Active;
}
else if (v.Count == 0)
{
cc = new CaseContract();
cc.CaseClassID = cr.CaseClassID;
cc.ContractID = cr.ContractID;
cc.Active = cr.Active;
}
else
{
//Error Logic
}
recordsToBePersisted.Add(cc);
}
//clean all cache
//insert all values from recordsToBePersisted
caseContract.Cache.Clear();
foreach (CaseContract i in recordsToBePersisted)
{
caseContract.Insert(i);
}
del();
}

Closing Case in Acumatica through API

I want to close the case in Partners Portal remotely using Web API, whenever I close the case in my (client) side. I was able to implement the code but ran into below issue.
It is changing the status and resolution of the case in Partners Portal but Close Case button is enabled and it is visible in My Open Case bucket. Please let me know if I can close the case remotely using Web API or if I am missing anything.
protected virtual void CRCase_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var caseRow = (CRCase)e.Row;
if (caseRow != null)
{
if (caseRow.Status == "C") // Closed
{
string cloud9CaseCD = null;
cloud9CaseCD = CRCaseForCreate.Current.CaseCD;
string acumaticaCaseCD = string.Empty;
CSAnswers aCCaseNoAttribute = PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>,
And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>>>>.Select(new PXGraph(), CRCaseForCreate.Current.NoteID, "ACCASENO");
if (aCCaseNoAttribute != null)
{
acumaticaCaseCD = aCCaseNoAttribute.Value;
if(!string.IsNullOrEmpty(acumaticaCaseCD))
{
SP203000WS.Screen context = new SP203000WS.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "https://sso.acumatica.com/Soap/SP203000.asmx";
PartnerPortalCreds loginCreds = GetCreds();
string username = loginCreds.PARTPRTUSE;
string password = loginCreds.PARTPRTPAS;
SP203000WS.LoginResult result = context.Login(username, password);
SP203000WS.Content CR306000 = context.GetSchema();
context.Clear();
SP203000WS.Content[] CR306000Content = context.Submit
(
new SP203000WS.Command[]
{
new SP203000WS.Value
{
Value = acumaticaCaseCD,
LinkedCommand = CR306000.Case.CaseID
},
new SP203000WS.Value
{
Value = "C",
LinkedCommand = new SP203000WS.Field { FieldName="Status", ObjectName="Case"}
},
new SP203000WS.Value
{
Value = "RD",
LinkedCommand = new SP203000WS.Field { FieldName="Resolution", ObjectName="Case"}
},
CR306000.Actions.Submit,
CR306000.Case.CaseID
}
);
context.Logout();
}
}
}
}
}
Tried below code using CloseCase Action: -
protected virtual void CRCase_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var caseRow = (CRCase)e.Row;
if (caseRow != null)
{
if (caseRow.Status == "C") // Closed
{
string cloud9CaseCD = null;
cloud9CaseCD = CRCaseForCreate.Current.CaseCD;
string acumaticaCaseCD = string.Empty;
CSAnswers aCCaseNoAttribute = PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>,
And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>>>>.Select(new PXGraph(), CRCaseForCreate.Current.NoteID, "ACCASENO");
if (aCCaseNoAttribute != null)
{
acumaticaCaseCD = aCCaseNoAttribute.Value;
if (!string.IsNullOrEmpty(acumaticaCaseCD))
{
SP203010WS.Screen context = new SP203010WS.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "https://sso.acumatica.com/Soap/SP203010.asmx";
PartnerPortalCreds loginCreds = GetCreds();
string username = loginCreds.PARTPRTUSE;
string password = loginCreds.PARTPRTPAS;
SP203010WS.LoginResult result = context.Login(username, password);
SP203010WS.Content CR306000 = context.GetSchema();
context.Clear();
var commands1 = new SP203010WS.Command[]
{
new SP203010WS.Value
{
Value = acumaticaCaseCD,
LinkedCommand = CR306000.Case.CaseID
},
new SP203010WS.Value
{
Value = "Yes",
LinkedCommand = CR306000.Case.ServiceCommands.DialogAnswer, Commit = true
},
CR306000.Actions.CloseCase
};
var data = context.Submit(commands1);
context.Logout();
}
}
}
}
}
In the below image you can see that the case is already closed but Close Case menu button is still visible.
Close Case Confirmation Dialogbox on Partners Portal. How should I answer this dialogbox programatically while closing the case using Web API.
Have you tried to invoke Close action via Web API instead of changing values of the Status and Resolution fields? As far as I know, Close button on the Partner Portal updates support case Status to Open and Reason to Pending Closure. Then it's up to support personnel to manually close the case.
Finally found the solution. Updated the code for CloseCase (second code snippet). This will mark the case as Pending Closure in Partners Portal.

I use sqldependency AND signalR AND thread but it goes on infinite loop

I use sqldependency AND signalR AND thread but it goes on infinite loop
combine BackgroundWorker in global.aspx and sqldependency and signalR
I dont know about problem please help me.
void Application_Start(object sender, EventArgs e)
{
//var session = HttpContext.Current.Session;
//if (session != null && HttpContext.Current != null)
//{
try
{
CSASPNETBackgroundWorker.BackgroundWorker worker = new CSASPNETBackgroundWorker.BackgroundWorker();
worker.DoWork += new CSASPNETBackgroundWorker.BackgroundWorker.DoWorkEventHandler(worker_DoWork);
worker.RunWorker(null);
// This Background Worker is Applicatoin Level,
// so it will keep working and it is shared by all users.
Application["worker"] = worker;
// Code that runs on application startup
}
catch { }
// }
System.Data.SqlClient.SqlDependency.Start(connectionstring);
}
string user_id;
void worker_DoWork(ref int progress,
ref object _result, params object[] arguments)
{
// Do the operation every 1 second wihout the end.
while (true)
{
Random rand = new Random();
int randnum = rand.Next(5000, 20000);
Thread.Sleep(randnum);
// This statement will run every 1 second.
// string user_id = "";
// if (HttpContext.Current != null && HttpContext.Current.Session != null)
{
// user_id = "22";// HttpContext.Current.Session["userId"].ToString();
user_id = ConfigurationManager.AppSettings["session_user_id"].ToString();
updatealarm(user_id);
}
// Other logic which you want it to keep running.
// You can do some scheduled tasks here by checking DateTime.Now.
}
}
AND
public class AlarmInfoRepository {
string connectionstr = ConfigurationManager.ConnectionStrings["officeConnectionString"].ConnectionString;
public IEnumerable GetData(string user_id)
{
using (SqlConnection connection = new SqlConnection(connectionstr))
{
//PersianCalendar jc = new PersianCalendar();
//string todayStr = jc.GetYear(DateTime.Now).ToString("0000") + "/" + jc.GetMonth(DateTime.Now).ToString("00") + "/" +
// jc.GetDayOfMonth(DateTime.Now).ToString("00");
//string timeStr = String.Format("{0:00}:{1:00}:{2:00}", jc.GetHour(DateTime.Now.AddSeconds(10)), jc.GetMinute(DateTime.Now.AddSeconds(10)), jc.GetSecond(DateTime.Now.AddSeconds(10)));
if (connection.State == ConnectionState.Closed)
connection.Open();
using (SqlCommand command = new SqlCommand(#"SELECT dbo.[web_alarmkartable].[id],dbo.[web_alarmkartable].peygir_id,dbo.[web_alarmkartable].user_id,
dbo.[web_alarmkartable].[content],dbo.[web_alarmkartable].[latestcreate_date],dbo.[web_alarmkartable].[latestcreate_time],
dbo.[web_alarmkartable].[firstcreate_date],dbo.[web_alarmkartable].[firstcreate_time],dbo.[web_alarmkartable].[duration],
dbo.[web_alarmkartable].[periodtype_id],dbo.[web_alarmkartable].[period],ISNULL(dbo.[web_alarmkartable].[color],'') AS color,dbo.[web_alarmkartable].id_tel FROM dbo.[web_alarmkartable] where dbo.[web_alarmkartable].content !='' AND dbo.[web_alarmkartable].content IS NOT NULL
AND (dbo.[web_alarmkartable].seen IS NULL OR dbo.[web_alarmkartable].seen =0) AND (dbo.[web_alarmkartable].expier IS NULL OR dbo.[web_alarmkartable].expier =0 )
AND (dbo.[web_alarmkartable].del=0 OR dbo.[web_alarmkartable].del IS NULL) AND dbo.[web_alarmkartable].user_id=" + user_id, connection))
{
// Make sure the command object does not already have
// a notification object associated with it.
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()
.Select(x => new AlarmInfo()
{
id = x.GetInt32(0),
peygir_id = x.GetInt32(1),
user_id = x.GetInt32(2),
content = x.GetString(3),
latestcreate_date = x.GetString(4),
latestcreate_time = x.GetString(5),
firstcreate_date = x.GetString(6),
firstcreate_time = x.GetString(7),
duration = x.GetDecimal(8),
periodtype_id = x.GetInt32(9),
period = x.GetDecimal(10),
color = x.GetString(11),
id_tel = x.GetInt32(12)
}).ToList();
}
//if (connection.State == ConnectionState.Open)
// connection.Close();
}
}
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if ((e.Info.ToString() == "Insert" || e.Info.ToString() == "Update") && e.Type == SqlNotificationType.Change)
AlermHub.Show(e.Info.ToString());
}
}
AND

Resources