Workflow C# string function error in Docusign - docusignapi

I have an code issue in docusign.
In my calculation step I have created and input and output code.
When I run the template and checking the "incoming data" xml in the workflow I have an error message displayed:
<In_80_stackTrace>Exception: at ADEXS.DynamicCode.DynamicClassD_3447d8ccd49f4631b91c31df53e249e7.DynamicMethodD_dcb572b7876d400683579290c5918f06(DynamicContext _context)</In_80_stackTrace>
I don't know how to fix this that it will show only the
logError("In_80_error", "Data node //CategoryName is missing");
when no data is in the node.
Below are the details - my input code:
//In_80 - ESP_CategoryName_Description
string In_80 = "";
{
try
{
if (incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText == null)
{
logError("In_80_error", "Data node //CategoryName is missing");
}
else if (incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText != null)
{
In_80 = incomingDataRoot.SelectSingleNode("//CategoryName[node()]").InnerText;
}
}
catch (Exception e)
{
//logError("In_80_error", "Exception: Message:" + e.Message +" Inner Exception: "+ e.InnerException +" StackTrace: "+ e.StackTrace +" Source: "+ e.Source +" Data: "+ e.Data);
logError("In_80_stackTrace", "Exception: " + e.StackTrace);
}
}
Here is the output code:
//OUT_92 - ESP_CategoryName_Description
var OUT_92 = In_80;
if (In_80 == "")
{
logError("OUT_92_error", "Error reading In_80");
} else {
XmlElement elem = incomingDataRoot.OwnerDocument.CreateElement("OUT_92");
string p_category = "";
int i = 1;
foreach (char item in In_80)
{
if (Char.IsLetter(item))
{
if (i == 1)
{
p_category += item.ToString().ToUpper();
}
else
{
p_category += item.ToString().ToLower();
}
i++;
}
else
{
if (item == ' ')
{
i = 1;
}
p_category += item.ToString();
}
}
OUT_92 = p_category;
elem.InnerText = OUT_92.ToString();
elem.SetAttribute("Name", "ESP_CategoryName_Description");
incomingDataRoot.SelectSingleNode("/Root/Params/TemplateFieldData/Calculation_Results").AppendChild(elem);
}
In incoming data OUT part I'm getting
<OUT_92_error>Error reading In_80</OUT_92_error>
where I assume that its because something is wrong with the input code part?
Thank you for your help!

Related

I have this array class that is not removing items after re-running my recyclerview

The below class is used in an array.
package com.example.ShivitoMGO;
public class RoomTable {
public String RoomName,UpDown,minmaxint;
}
Main Activity
static ArrayList <RoomTable> CountCheck = new ArrayList<>();
public void playerup(View vvv){
st_spinner = v1.findViewById(R.id.spinner);
st_reportLayout = v1.findViewById(R.id.reportlayout);
st_Leanervidimg = v1.findViewById(R.id.Linearvidcopy);
TextView roomname = v1.findViewById(R.id.action_Players1);
RoomTable roomtb = new RoomTable();
if (CountCheck.size() == 0){
//playerupdown = "up";
Toast.makeText(this, "Will notify when " + mRooms.get(position1) + " players increase #" + mRoomSize.get(position1), Toast.LENGTH_LONG).show();
String[] minmaxval = mRoomSize.get(position1).split("/");
CountCheckint = Integer.parseInt(minmaxval[0].trim());
//CountCheck = (String) mRooms.get(position1);
roomtb.RoomName = (String) mRooms.get(position1);
roomtb.minmaxint = minmaxval[0].trim();
roomtb.UpDown = "up";
Log.d("added: ", "it was added");
CountCheck.add(roomtb);
Log.d("RoomTableadd: ",roomtb.RoomName+ " " + roomtb.minmaxint +" " +roomtb.UpDown);
st_reportLayout.setVisibility(View.GONE);
Log.d("Longclickhere: ", mRoomSize.get(position1));
Log.d("RoomNameCount ", String.valueOf(CountCheck.get(0).RoomName));
}else {
int exist1 = 0;
int poss;
for (int i = 0; i < CountCheck.size(); i++) {
if (roomname.getText() == CountCheck.get(i).RoomName) {
Log.d("RoomNametxt: " , CountCheck.get(i).RoomName);
Log.d("RoomNametxt: ", (String) roomname.getText());
Toast.makeText(this, "Notification " + CountCheck.get(i).RoomName + " OFF!", Toast.LENGTH_LONG).show();
Log.d("Removed item: ", String.valueOf(CountCheck.size()));
CountCheck.remove(i);
Log.d("Removed item: ", String.valueOf(CountCheck.size()));
st_reportLayout.setVisibility(View.GONE);
exist1 = 1;
poss = i;
} else {
exist1 = 0;
}
}
if (exist1 == 0) {
Toast.makeText(this, "Will notify when " + mRooms.get(position1) + " players increase #" + mRoomSize.get(position1), Toast.LENGTH_LONG).show();
String[] minmaxval = mRoomSize.get(position1).split("/");
CountCheckint = Integer.parseInt(minmaxval[0].trim());
//CountCheck = (String) mRooms.get(position1);
roomtb.RoomName = (String) mRooms.get(position1);
roomtb.minmaxint = minmaxval[0].trim();
roomtb.UpDown = "up";
Log.d("added: ", "it was added");
CountCheck.add(roomtb);
Log.d("RoomTableadd: ", roomtb.RoomName + " " + roomtb.minmaxint + " " + roomtb.UpDown);
st_reportLayout.setVisibility(View.GONE);
}
Log.d("CountSize: ", String.valueOf(CountCheck.size()));
for (int xb = 0;xb<CountCheck.size();xb++) {
try {
Log.d("RoomNameCount ", String.valueOf(CountCheck.get(xb).RoomName));
} catch (Exception e) {
Log.d("Out of range ", String.valueOf(e));
}
}
}
}
Recycler-View
#Override
public boolean onLongClick(View v) {
// Launch your web intent
if (CountCheck.size() != 0){
Log.d("Longclickhere: ",mRoomSize.get(position));
Toast.makeText(mContext, mRoomSize.get(position), Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "Will notify when "+mRooms.get(position)+" players decrease", Toast.LENGTH_SHORT).show();
String[] minmaxval = mRoomSize.get(position).split("/");
MainActivity.CountCheckint = Integer.parseInt(minmaxval[0].trim());
} else{
//MainActivity.CountCheck = "";
Toast.makeText(mContext, "Player Decrease notification OFF", Toast.LENGTH_SHORT).show();
}
return true;
In this app the recycler view creates the "rooms" and if the room is selected the textview and 2 other values are put in to the RoomTable. these are stored and used in a service to check if ether of the other to values change. Everything works as intended unless i use the swip-to-refresh witch runs the recycler-view again. If i do not refresh and i select the same item in the recycler-view it will remove it from CountCheck . However if i run the refresh and select the same recycler-view item that i selected previously it will add it instead of removing it. This Makes no since to me because i use a for loop to Check the CountCheck.get(i).RoomName aka the textview and if the names are the same then my if statement will remove instead of add. is it somehow possible i'm ending up with 2 CountCheck Objects????? with the same name???? Please I'm out of ideas on this one. Thanks.
I dont remember why. Maybe someone can explain but i changed this line
if (roomname.getText() == CountCheck.get(i).RoomName)
To this
if (roomname.getText().equals(CountCheck.get(i).RoomName));
and that fixed the issue. please let me know the difference if you are reading this.

The remote server returned an error: (401) Unauthorized - CSOM - OAuth - after specific time

I am trying to get permissions assigned to each document from the document library using csom in console application. Console app is running fine for almost one hour and post that I get error : "The remote server returned an error: (401) Unauthorized."
I registered an app in SharePoint and I'm using Client ID & Client Secret Key to generate Client Context. Here is the code to get the client context
public static ClientContext getClientContext()
{
ClientContext ctx = null;
try
{
ctx = new AuthenticationManager().GetAppOnlyAuthenticatedContext(SiteUrl, ClientId, ClientSecret);
ctx.RequestTimeout = 6000000;
ctx.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.UserAgent = "NONISV|Contoso|GovernanceCheck/1.0";
};
}
catch (Exception ex)
{
WriteLog("Method-getClientContext, Error - " + ex.Message);
}
return ctx;
}
Here is the code which is getting all the assignments assigned to document in document library.
static StringBuilder excelData = new StringBuilder();
static void ProcessWebnLists()
{
try
{
string[] lists = { "ABC", "XYZ", "DEF", "GHI"};
foreach (string strList in lists)
{
using (var ctx = getClientContext())
{
if (ctx != null)
{
Web web = ctx.Site.RootWeb;
ListCollection listCollection = web.Lists;
ctx.Load(web);
ctx.Load(listCollection);
ctx.ExecuteQuery();
List list = web.Lists.GetByTitle(strList);
ctx.Load(list);
ctx.ExecuteQuery();
Console.WriteLine("List Name:{0}", list.Title);
var query = new CamlQuery { ViewXml = "<View/>" };
var items = list.GetItems(query);
ctx.Load(items);
ctx.ExecuteQuery();
foreach (var item in items)
{
var itemAssignments = item.RoleAssignments;
ctx.Load(item, i => i.DisplayName);
ctx.Load(itemAssignments);
ctx.ExecuteQuery();
Console.WriteLine(item.DisplayName);
string groupNames = "";
foreach (var assignment in itemAssignments)
{
try
{
ctx.Load(assignment.Member);
ctx.ExecuteQuery();
groupNames += "[" + assignment.Member.Title.Replace(",", " ") + "] ";
Console.WriteLine($"--> {assignment.Member.Title}");
}
catch (Exception e)
{
WriteLog("Method-ProcessWebnLists, List-" + list.Title + ", Document Title - " + item.DisplayName + ", Error : " + e.Message);
WriteLog("Method-ProcessWebnLists, StackTrace : " + e.StackTrace);
}
}
excelData.AppendFormat("{0},{1},ITEM,{2}", list.Title, (item.DisplayName).Replace(",", " "), groupNames);
excelData.AppendLine();
}
}
excelData.AppendLine();
}
}
}
catch (Exception ex)
{
WriteLog("Method-ProcessWebnLists, Error : " + ex.Message);
WriteLog("Method-ProcessWebnLists, StackTrace : " + ex.StackTrace.ToString());
}
}
Can anyone suggest what else I am missing in this or what kind of changes do I need to make to avoid this error?
The process is taking too much time so I want my application to keep running for couple of hours.
Thanks in advance!
Is there a reason why getClientContext() is inside the foreach loop?
I encountered this error before.
I added this to solve mine.
public static void ExecuteQueryWithIncrementalRetry(this ClientContext context, int retryCount, int delay)
{
int retryAttempts = 0;
int backoffInterval = delay;
if (retryCount <= 0)
throw new ArgumentException("Provide a retry count greater than zero.");
if (delay <= 0)
throw new ArgumentException("Provide a delay greater than zero.");
while (retryAttempts < retryCount)
{
try
{
context.ExecuteQuery();
return;
}
catch (WebException wex)
{
var response = wex.Response as HttpWebResponse;
if (response != null && response.StatusCode == (HttpStatusCode)429)
{
Console.WriteLine(string.Format("CSOM request exceeded usage limits. Sleeping for {0} seconds before retrying.", backoffInterval));
//Add delay.
System.Threading.Thread.Sleep(backoffInterval);
//Add to retry count and increase delay.
retryAttempts++;
backoffInterval = backoffInterval * 2;
}
else
{
throw;
}
}
}
throw new MaximumRetryAttemptedException(string.Format("Maximum retry attempts {0}, have been attempted.", retryCount));
}
Basically, this code backs off for a certain time/interval before executing another query, to prevent throttling.
So instead of using ctx.ExecuteQuery(), use ctx.ExecuteQueryWithIncrementalRetry(5, 1000);
Further explanation here
https://learn.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online

Include Data In A Response/Reply From A Primefaces Push

Is there a way to include data from the front-end to send to the back end, perhaps in the reply.completed argument, such that if a condition was not met, the front end can inform the backend of the status and the backend and do something with that data? And if so, how?
From the back-end:
Reply reply = new Reply() {
#Override
public void completed(String arg0) {
System.out.println("Reply received: " + arg0);
}
};
summary = this.getText("report.ready.view").replace("{0}", reportName);
reportLink = this.getExternalContextRoot() + reportLink + (!reportLink.contains("?") ? "?reportId=" : "&reportId=") + savedReportStatus.getSavedReportStatusId();
detail = "<a href='" + reportLink + "'>" + this.getText("click.to.view") + "</a>";
facesMessage = new FacesMessage(severity, summary, detail);
eventBus.publish(channel, facesMessage, reply);
From the front-end:
<p:socket onMessage="handleMessage" channel="/reports/#{userSessionBean.userID}" autoConnect="true"/>
<script type="text/javascript">
function handleMessage(message) {
if (DO SOME CHECK) {
if (message.severity == 'INFO 0') {
message.severity = 'info';
} else if (message.severity == 'WARN 1') {
message.severity = 'warn';
} else if (message.severity == 'ERROR 2') {
message.severity = 'error';
} else if (message.severity == 'FATAL 3') {
message.severity = 'fatal';
}
PF('reportsGrowl').show([message]);
updateViewedReports();
} else {
SEND THE BACK-END INFORMATION INDICATING THE CHECK FAILED AND THE MESSAGE WAS NOT SHOWN
}
}
$(document).ready(function () {
updateViewedReports();
});
</script>

CSJS addCallback always runs SSJS

Can someone please shed some light on why this CSJS code is always running my SSJS code regardless of the CSJS seeming to return true or false?
CSJS code
message = "Starting Settle ATM Process..."
$(".infoMessage").text(message);
atmID = $("input.atmID").val(); //pull from hidden input
var deferred = atmRPC.closeATMFirstSettle();
deferred.addCallback(function(result){
if (result == "false") {
alert("Close command failed during 1st Settle ATM process. System will retry...");
var insideDeferred = atmMRPC.closeATMSecondSettle();
insideDeferred.addCallback(function(result) {
if (result == "false") {
message = "Close command failed during Settle ATM process. Please try again later."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
return false;
} else if(result == "true"){
var deferred = atmRPC.settleATMFirst();
deferred.addCallback(function(result){
if (result == "false") {
alert("Settlement failed during 1st attempt. System will retry...");
var insideDeferred = atmMRPC.settleATMSecond();
insideDeferred.addCallback(function(result) {
if (result == "false") {
message = "Settlement failed. Please try again later."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
return false;
} else if(result == "true"){
message = atmID + " has been successfully Settled."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
// return true;
}
})
} else if(result == "true"){
message = atmID + " has been successfully Settled."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
// return true;
}
})
}
})
} else if(result == "true"){
var deferred = atmRPC.settleATMFirst();
deferred.addCallback(function(result){
if (result == "false") {
alert("Settlement failed during 1st attempt. System will retry...");
var insideDeferred = atmMRPC.settleATMSecond();
insideDeferred.addCallback(function(result) {
if (result == "false") {
alert("Settlement failed during 1st attempt. System will retry...");
message = "Settlement failed. Please try again later."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
return false;
} else if(result == "true"){
message = atmID + " has been successfully Settled."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
// return true;
}
})
} else if(result == "true"){
message = atmID + " has been successfully Settled."
$(".infoMessage").text(message);
atmRPC.updateInfoMsg(message);
// return true;
}
})
}
})
closeATMFirsSettle and closeATMSecondSettle are identical with exception of the boolean variable
if(atmBean.atmStatus == "OPEN" || atmBean.atmStatus == "WOUNDED") {
var firstTry:boolean = atmBean.closeATM(atmBean.atmID, userBean.userID);
return firstTry.toString();
} else if(atmBean.atmStatus == "CLOSED") {
return "true";
} else {
return "false";
}
settleATMFirst and settleATMSecond are identical with exception of the boolean variable
sessionScope.infoMsg = null;
try {
if(atmBean.atmAmountReceived == null) {
var settleAmt:Integer = Integer.parseInt(atmBean.atmTodaySettlementAmt);
} else {
var settleAmt:Integer = Integer.parseInt(atmBean.atmAmountReceived);
}
} catch(e) {
message:String = "1st Settle ATM Amount Error: " + e;
logInfo(message);
return sessionScope.infoMsg = message;
}
var firstTry:boolean = atmBean.settleATM(atmBean.atmID, userBean.userID, settleAmt);
return firstTry.toString();
atmBean.settleATM
public boolean settleATM(String atmId, String employeeId, Integer settlementAmount, String attempt){
//This method called by RPC control from client JS
AtmOperationSettlementResult result = null;
boolean returnValue = false;
try {
result = AtmTerminalUtil.settleAtm(atmID, employeeId, settlementAmount);
returnValue = result.getSuccess();
if(attempt.equals("Second")) {
System.out.println("ATM Bean - Second Attempt");
if(!returnValue) {
handleATMError(result);
}
}
} catch(Exception e) {
System.out.println(e);
}
//saveATMHistory();
return returnValue; //return status of operation to UI
}
I know the SSJS in the Server tab is always being ran because the log entries show the value of a viewScope that is set if the atmBean.settleATM returns a false.
Sorry, didn't realize until the last comment that everyone may be thinking the SSJS code I'm talking about is in the RPC, but I'm referring to the Server tab.

Error while adding entity object to DBContext object called from Parallel.Foreach loop

Error :
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
Object reference not set to an instance of an object. at
System.Data.Objects.ObjectStateManager.DetectConflicts(IList1
entries) at System.Data.Objects.ObjectStateManager.DetectChanges()
at System.Data.Entity.Internal.InternalContext.DetectChanges(Boolean
force) at
System.Data.Entity.Internal.Linq.InternalSet1.ActOnSet(Action action,
EntityState newState, Object entity, String methodName) at
System.Data.Entity.Internal.Linq.InternalSet1.Add(Object entity)
at System.Data.Entity.DbSet1.Add(TEntity entity) at
ESHealthCheckService.BusinessFacade.BusinessOperationsLayer.AddErrorToDbObject(Exception
ex, Server serverObj, Service windowsServiceObj)
the message resource is present but the message is not found in the string/message table
public void CheckForServerHealth()
{
businessLayerObj.SetStartTimeWindowsService();
List<ServerMonitor> serverMonitorList = new List<ServerMonitor>();
serverList = businessLayerObj.GetServerList();
Parallel.ForEach(
serverList,
() => new List<ServerMonitor>(),
(server, loop, localState) =>
{
localState.Add(serverStatus(server, new ServerMonitor()));
return localState;
},
localState =>
{
lock (serverMonitorList)
{
foreach (ServerMonitor serverMonitor in localState)
{
serverMonitorList.Add(serverMonitor);
}
}
});
businessLayerObj.SaveServerHealth(serverMonitorList);
}
public ServerMonitor serverStatus(Server serverObj, ServerMonitor serverMonitorObj)
{
if (new Ping().Send(serverObj.ServerName, 30).Status == IPStatus.Success)
{
serverMonitorObj.Status = true;
try
{
PerformanceCounter cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total", serverObj.ServerName);
serverMonitorObj.CPUUtlilization = (cpu.NextValue());
}
catch (Exception ex)
{
businessLayerObj.AddErrorObjectToStaticList(ex, serverObj);
}
serverMonitorObj.ServerID = serverObj.ServerID;
try
{
string[] diskArray = serverObj.DriveMonitor.ToString().Split(':');
if (diskArray != null && diskArray.Contains("NA"))
{
serverMonitorObj.DiskSpace = "NA";
}
else
{
serverMonitorObj.DiskSpace = ReadFreeSpaceOnNetworkDrives(serverObj.ServerName, diskArray);
}
}
catch (Exception ex)
{
businessLayerObj.AddErrorObjectToStaticList(ex, serverObj);
}
serverMonitorObj.CreatedDateTime = DateTime.Now;
}
else
{
serverMonitorObj.Status = false;
serverMonitorObj.ServerID = serverObj.ServerID;
//return serverMonitorObj;
}
return serverMonitorObj;
}
public void AddErrorObjectToStaticList(Exception ex, Server serverObj = null, Service windowsServiceObj = null)
{
EShelathLoging esLogger = new EShelathLoging();
esLogger.CreateDatetime = DateTime.Now;
if (ex.InnerException != null)
{
esLogger.Message = (windowsServiceObj == null ? ex.InnerException.Message : ("Service Name : " + windowsServiceObj.ServiceName + "-->" + ex.InnerException.Message));
//esLogger.Message = "Service Name : " + windowsServiceObj.ServiceName + "-->" + ex.InnerException.Message;
esLogger.StackTrace = (ex.InnerException.StackTrace == null ? "" : ex.InnerException.StackTrace);
}
else
{
esLogger.Message = (windowsServiceObj == null ? ex.Message : ("Service Name : " + windowsServiceObj.ServiceName + "-->" + ex.Message));
//esLogger.Message = "Service Name : " + windowsServiceObj.ServiceName + "-->" + ex.Message;
esLogger.StackTrace = ex.StackTrace;
}
if (serverObj != null)
{
esLogger.ServerName = serverObj.ServerName;
}
try
{
lock (lockObject)
{
esHealthCheckLoggingList.Add(esLogger);
}
}
catch (Exception exe)
{
string logEntry = "Application";
if (EventLog.SourceExists(logEntry) == false)
{
EventLog.CreateEventSource(logEntry, "Windows and IIS health check Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = logEntry;
eventLog.WriteEntry(exe.Message + " " + exe.StackTrace, EventLogEntryType.Error);
}
}
And then the below function is called to add objects from static list to the db object.
public void AddErrorToDbObject()
{
try
{
foreach (EShelathLoging eslogObject in esHealthCheckLoggingList)
{
lock (lockObject)
{
dbObject.EShelathLogings.Add(eslogObject);
}
}
}
catch (DbEntityValidationException exp)
{
string logEntry = "Application";
if (EventLog.SourceExists(logEntry) == false)
{
EventLog.CreateEventSource(logEntry, "Windows and IIS health check Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = logEntry;
eventLog.WriteEntry(exp.Message + " " + exp.StackTrace, EventLogEntryType.Error);
}
catch (Exception exe)
{
string logEntry = "Application";
if (EventLog.SourceExists(logEntry) == false)
{
EventLog.CreateEventSource(logEntry, "Windows and IIS health check Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = logEntry;
eventLog.WriteEntry(exe.Message + " " + exe.StackTrace, EventLogEntryType.Error);
}`enter code here`
}
DbSet<T> is not thread-safe, so you can't use it from multiple threads at the same time. It seems you're trying to fix that by using a lock, but you're doing that incorrectly. For this to work, all threads have to share a single lock object. Having separate lock object for each thread, like you do now, won't do anything.
Please note that I received the same exception with the application I was working on, and determined that the best way to resolve the issue was to add an AsyncLock, because of what #svick mentioned about how DbSet is not threadsafe. Thank you, #svick!
I'm guessing that your DbContext is inside your businessLayerObj, so here is what I recommend, using Stephen Cleary's excellent Nito.AsyncEx (see https://www.nuget.org/packages/Nito.AsyncEx/):
using Nito.AsyncEx;
// ...
private readonly AsyncLock _dbContextMutex = new AsyncLock();
public void CheckForServerHealth()
{
using (await _dbContextMutex.LockAsync().ConfigureAwait(false))
{
await MyDbContextOperations(businessLayerObj).ConfigureAwait(false);
}
}
private async Task MyDbContextOperations(BusinessLayerClass businessLayerObj)
{
await Task.Run(() =>
{
// operations with businessLayerObj/dbcontext here...
});
}

Resources