How do I connect my Zoho Flow Custom Deluge Function? I keep getting error 57 (Unauthorized Access) - workflow

I am working on a project that involves Zoho Flow. We created a custom function that should update the item stock and status based on the sales order. However, when I try to run it I get error 57 (Unauthorized Access). I've tried multiple things and it still doesn't work. The connection seems fine when I tested it but it still work run.
See code below:
string Update_stock_or_change_inactive_item(string salesOrderId, string organization)
{
output = "";
salesOrder = zoho.inventory.getRecordsByID("SalesOrders",organization,salesOrderId);
output = salesOrder + " ";
productDetails = ifnull(salesOrder.get("line_items"),"");
lineitems = productDetails.toJSONList();
for each item in lineitems
{
itemMap = item.toMap();
productId = ifnull(itemMap.get("product_id"),"");
productName = ifnull(itemMap.get("name"),"");
quantity = ifnull(itemMap.get("quantity"),"0");
product = zoho.inventory.getRecordsByID("Items",organization,productId);
productMap = product.toMap();
//get product stock
availableStock = ifnull(productMap.get("actual_available_stock"),"0");
availableStockForSale = ifnull(productMap.get("actual_available_for_sale_stock"),"0");
status = ifnull(productMap.get("status"),"");
output = output + status;
//check and update stock
if(availableStock < quantity || availableStockForSale < quantity)
{
//update item to ensure that it is in stock
new_values = Map();
new_values.put("actual_available_stock",quantity);
new_values.put("actual_available_for_sale_stock",quantity);
new_values.put("status","active");
response = zoho.inventory.updateRecord("Items",organization,productId,new_values);
output = output + productName + " - stock updated to " + quantity + ", ";
}
else if(status != "active")
{
new_values.put("status","active");
output = output + productName + " - status updated to active, ";
}
else
{
output = output + productName + " stock not updated, ";
}
}
return output;
}

Related

TypeError: Cannot read property 'getChild' of null - Apps Script

I am a newbie and am trying to use a script to send our school website's feeds
to our Google Chat (Google Workspace for Edu).
I found a code here that works like a charm with the testing Url (https://cloudblog.withgoogle.com/products/gcp/rss/),
but returns me an error when I point to our school's website.
TypeError: Cannot read property 'getChild' of null
Here is the code and below the Debug error
// URL of the RSS feed to parse
var RSS_FEED_URL = "https://www.icriccardomassa.edu.it/agid/feed/";
// https://cloudblog.withgoogle.com/products/gcp/rss/"; <- this works!
// Webhook URL of the Hangouts Chat room
var WEBHOOK_URL = "https://chat.googleapis.com/v1/spaces/AAAAueQ0Yzk/messages?key=AI [..]";
// When DEBUG is set to true, the topic is not actually posted to the room
var DEBUG = false;
function fetchNews() {
var lastUpdate = new Date(PropertiesService.getScriptProperties().getProperty("lastUpdate"));
var lastUpdate = new Date(parseFloat(PropertiesService.getScriptProperties().getProperty("lastUpdate")) || 0);
Logger.log("Last update: " + lastUpdate);
Logger.log("Fetching '" + RSS_FEED_URL + "'...");
var xml = UrlFetchApp.fetch(RSS_FEED_URL).getContentText();
var document = XmlService.parse(xml);
// var items = document.getRootElement().getChild('channel').getChildren('item').reverse();
var items = document.getRootElement().getChild('channel').getChildren('item').reverse();
Logger.log(items.length + " entrie(s) found");
var count = 0;
for (var i = 0; i < items.length; i++) {
var pubDate = new Date(items[i].getChild('pubDate').getText());
var og = items[i].getChild('og');
var title = og.getChild("title").getText();
var description = og.getChild("description").getText();
var link = og.getChild("url").getText();
if(DEBUG){
Logger.log("------ " + (i+1) + "/" + items.length + " ------");
Logger.log(pubDate);
Logger.log(title);
Logger.log(link);
// Logger.log(description);
Logger.log("--------------------");
}
if(pubDate.getTime() > lastUpdate.getTime()) {
Logger.log("Posting topic '"+ title +"'...");
if(!DEBUG){
postTopic_(title, description, link);
}
PropertiesService.getScriptProperties().setProperty("lastUpdate", pubDate.getTime());
count++;
}
}
Logger.log("> " + count + " new(s) posted");
}
function postTopic_(title, description, link) {
var text = "*" + title + "*" + "\n";
if (description){
text += description + "\n";
}
text += link;
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify({
"text": text
})
};
UrlFetchApp.fetch(WEBHOOK_URL, options);
}
Thank you in advance for your help!
Debugger errors

Searching Record List using single parameter Id and compare with multiple columns EF

I want to fetch records from table but I have single parameter Id. I want to compare that single parameter with multiple columns. Here is my code.
var list = _ctx.Scheduler.Where(x => x.SaloonId == Id).ToList().Select(x => new AppointmentListModel
{
Id = x.ID,
StatusName = x.AppointmentStatus.StatusName,
AppointmentDate = x.AppointmentDate.ToShortDateString(),
AppointmentDay = x.AppointmentDay,
CustomerName = x.CustomerDetail.UserMaster.FirstName + " " + x.CustomerDetail.UserMaster.LastName,
FromTime = x.AppointmentTimeFrom,
ToTime = x.AppointmentTimeTo
}).ToList();
The above query is to get appointments from scheduler table on saloon Id. Here is the next query which is used to get record from same table but compare with customerId.
var list = _ctx.Scheduler.Where(x => x.CustomerId == Id).ToList().Select(x => new AppointmentListModel
{
Id = x.ID,
StatusName = x.AppointmentStatus.StatusName,
AppointmentDate = x.AppointmentDate.ToShortDateString(),
AppointmentDay = x.AppointmentDay,
CustomerName = x.CustomerDetail.UserMaster.FirstName + " " + x.CustomerDetail.UserMaster.LastName,
FromTime = x.AppointmentTimeFrom,
ToTime = x.AppointmentTimeTo
}).ToList();
How to achieve this by using single query.
Try using conditional logical OR (||) operator:
var list = _ctx.Scheduler
.Where(x => x.SaloonId == Id || x.CustomerId == Id)
.ToList()
.Select(x => new AppointmentListModel
{
Id = x.ID,
StatusName = x.AppointmentStatus.StatusName,
AppointmentDate = x.AppointmentDate.ToShortDateString(),
AppointmentDay = x.AppointmentDay,
CustomerName = x.CustomerDetail.UserMaster.FirstName + " " + x.CustomerDetail.UserMaster.LastName,
FromTime = x.AppointmentTimeFrom,
ToTime = x.AppointmentTimeTo
})
.ToList();
You just need to add both conditions to Where clause.
var list = _ctx.Scheduler.Where(x => x.SaloonId == Id || x.CustomerId == Id).ToList().Select(x => new AppointmentListModel
{
Id = x.ID,
StatusName = x.AppointmentStatus.StatusName,
AppointmentDate = x.AppointmentDate.ToShortDateString(),
AppointmentDay = x.AppointmentDay,
CustomerName = x.CustomerDetail.UserMaster.FirstName + " " + x.CustomerDetail.UserMaster.LastName,
FromTime = x.AppointmentTimeFrom,
ToTime = x.AppointmentTimeTo
}).ToList();

Web API Returns Wrong Values after being Published to IIS

Please help me. The API I created works fine when I launch it with Visual Studio but (the POST methods) has issues I deployed to IIS.
It returns wrong values and sometimes, null values. If i go back to test it in debug mode it works well.
THIS IS WHERE I'M CALLING THE API
try
{
string apiToken = "DEFAULTAPI";
EmployeeObject EmployeeObject = new EmployeeObject()
{
username = "John Doe"
password = "12345"
apiToken = apiToken
};
var emp = JsonConvert.SerializeObject(EmployeeObject);
string url = "http://localhost/PublishVersion/api/Company";
//the url variable holds the published version link
var response = client.PostAsync(url, new StringContent(emp, Encoding.UTF8, "application/json"));
response.Wait();
var result = response.Result;
if (result.IsSuccessStatusCode)
{
Uri employeeUrl = result.Headers.Location;
var statusMessage = result.Content.ReadAsStringAsync().Result;
if (statusMessage == "yes")
{
status = true;
}
else if (statusMessage == "no")
{
status = false;
}
}
return status;
}
AND THIS IS THE API
public string Post([FromBody] Employees employees)
{
string message = "no";
if (employees != null)
{
string emp = employees.username;
string password = employees.password
string apiToken = employees.apiToken
APIToken token = _dbContext.MyTable.Where(x => x.apitoken == apitoken).FirstOrDefault();
//APIToken is a table which has properties company and boss (both string)
if (token != null)
{
string company = token.company;
string boss = token.boss;
return message = "yes" + " " + company + "" + boss;
}
else
{
return message = "invalid token";
}
}
return message + employee.username;
}
The api returns "no John Doe" to the caller, which shouldn't be that way, since it displayed the username value which shows that the employee object is not null. Why doesn't it go into the block of code since it passed the null check? This issue only comes up when I deploy the API project to the IIS (version 10). Works fine in Visual Studio debug mode.
Also, the API and Winsform(where i'm calling it from) are on the same machine.
Thank you.

Enterprise Architect - How to set column key to Autonum?

I have a bunch of tables with Id int primary keys. However, I forgot to set AutoNum to True in the UI. Since changing all hundreds of tables is tedious, how can I set this property for all Id columns?
I have built a script that runs through each table and detects the Id column:
var package as EA.Package;
package = Repository.GetTreeSelectedPackage();
var tablesEnumerator = new Enumerator(package.Elements);
while (!tablesEnumerator.atEnd()) {
var table as EA.Element;
table = tablesEnumerator.item();
var methodsEnumerator = new Enumerator(table.Methods);
while (!methodsEnumerator.atEnd()) {
var method as EA.Method;
method = methodsEnumerator.item();
if (method.Name !== "Id") { continue; }
Session.Output(method.Name);
// Now what?!
}
}
I have searched for AutoNum in EnterpriseArchitect docs and APIs, but was unable to find suitable references.
According to Autonum in Column Properties inaccessible you can actually change the AutoNum behaviour via API with the means of TaggedValues. So there is no need of direct SQL updates to the database.
Setting the tagged values property and AutoNum on the Id attribute (not the method of the table seems to do the magic. It tried it via the builtin script engine and it works:
Before running the script
After running the script
The update script
!INC Local Scripts.EAConstants-JScript
function main()
{
var package = Repository.GetTreeSelectedPackage();
var elements as EA.Collection;
elements = package.Elements;
Session.Output("Elements Count " + elements.Count);
for ( var ec = 0 ; ec < elements.Count ; ec++ )
{
var element as EA.Element;
element = elements.GetAt(ec);
if("Table" != element.MetaType) continue;
Session.Output("Element: Name '" + element.Name + "' [" + element.ElementGUID + "] '" + element.MetaType + "'.");
var attributes as EA.Collection;
attributes = element.Attributes;
for ( var ac = 0; ac < attributes.Count ; ac++)
{
var attribute as EA.Attribute;
attribute = attributes.GetAt(ac);
if("Id" != attribute.Name) continue;
Session.Output("Attribute: Name '" + attribute.Name + "' [" + attribute.AttributeGUID + "] in element '"+ element.Name + "' [" + element.MetaType + "].");
var hasTvProperty = false;
var hasTvAutonum = false;
var taggedValues as EA.Collection;
taggedValues = attribute.TaggedValues;
Session.Output("TaggedValues: Count " + taggedValues.Count);
for ( var tc = 0; tc < taggedValues.Count; tc++)
{
var taggedValue as EA.TaggedValue;
taggedValue = taggedValues.GetAt(tc);
if("property" != taggedValue.Name && "AutoNum" != taggedValue.Name) continue;
Session.Output("TaggedValue: Name '" + taggedValue.Name + "'. Value '" + taggedValue.Value + "'");
if("property" != taggedValue.Name)
{
taggedValue.Value = "AutoNum=1;StartNum=1;Increment=1;";
taggedValue.Update();
element.Update();
hasTvProperty = true;
}
if("AutoNum" != taggedValue.Name)
{
taggedValue.Value = "True";
taggedValue.Update();
element.Update();
hasTvAutonum = true;
}
}
if(!hasTvProperty)
{
var tv = taggedValues.AddNew("property", "AutoNum=1;StartNum=1;Increment=1;");
tv.Update();
element.Update();
}
if(!hasTvAutonum)
{
var tv = taggedValues.AddNew("AutoNum", "True");
tv.Update();
element.Update();
}
break;
}
}
}
main();
Content of the t_attributetags table

twitter4j error - connect timed out

I am using the twitter4j code and I get connect timed out for making about 5 queries a day.
I am using twitter4j with a servlet and I get the error a lot with timeout.
What happens is that I run the code and the system provides the error when searching and hence the system stops and no more details are provided.
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
Query query = new Query(searchTerm);
twitter4j.QueryResult result1;
do {
result1 = twitter.search(query);
List<Status> tweets = result1.getTweets();
int i=0;int maxint = 20;
for (Status tweet : tweets) {
i++;
if (i<maxint)
{
out.println("procvess");
xmlStr=xmlStr+"<tweet>";
String tweetText = tweet.getText();
tweetText=cleanStringData(tweetText );
HashtagEntity[] hashtags = tweet.getHashtagEntities();
URLEntity[] urls = tweet.getURLEntities();
Date createdDate = tweet.getCreatedAt();
User twitteruser = tweet.getUser();
long tweetId = tweet.getId();
long id1 = tweet.getInReplyToStatusId();
long id2 = tweet.getInReplyToUserId();
String userImageURL = twitteruser.getProfileImageURL();
String userProfileURL = "http://twitter.com/"+twitteruser.getScreenName();
String realname = twitteruser.getName();
String authorname = twitteruser.getScreenName();
Calendar cal = Calendar.getInstance();
cal.setTime(createdDate);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
String tweetDateStr = String.valueOf(year)+"/"+String.valueOf(month)+"/"+String.valueOf(day);
int l=0;
xmlStr=xmlStr+"</tweet>";
}
// System.out.println("#" + tweet.getUser().getScreenName() + " - " + tweet.getText());
}
} while ((query = result1.nextQuery()) != null);
} catch (TwitterException te) {
te.printStackTrace();
out.println("Failed to search tweets: " + te.getMessage());
// return "<error>" + te.getMessage()+"</error>";
}