Problems with ajax_function i get an error - ajax

Hello stackowerflow people, ive got problem, im trying to use one of your community scripts, and i cant find out problem. I get error about this ajax_function, how can i solve it, or fix it please help, here is the script:
<script>
function editColumn(dbc)
{
var params = 'option=edit&dbc=' + dbc ;
var Divdbc = 'edit_' + dbc;
ajax_function('ajax_edit.php', params, Divdbc);
}
function saveColumn(dbc)
{
var value = document.getElementById('date_'+dbc).value;
var params = 'option=save&value=' + value + '&Id' + dbc ;
var Divdbc = 'edit_' + dbc;
ajax_function('ajax_edit.php', params, Divdbc);
}
</script>
And here is the error which i get:
ReferenceError: ajax_function is not defined
How can i possible create that ajax function to work with my script?

it means that the ajax_function() is not declared or not found
find this keyword in any of your files "function ajax_function()"
or
check if it needs to import the script that contains function ajax_function()
example:
<script src="thefile.js"></script>

Related

GAS sends multiple slack notifications

I'd like to send notifications to slack using Google Apps Scripts.
It's supposed to happen when any change is made on Gsheet but sometimes the program sends multiple notifications even after only a single change.
I guess my code has any fault or the triggers cause any problem - because I apply this function to more than one sheet.
But it doesn't happen "always", so is it an error caused by GAS specification?
My code is as below. Any idea or advice will be appreciated.
function slackNotification(sheetname,slack_channel){
Logger.log(sheetname)
var mySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetname);
var myActiveRange = mySheet.getActiveRange();
var lastRow = mySheet.getLastRow();
var pdfColumn = PDF_column_n
var checkColumn = slack_column_n
Logger.log(lastRow)
var unslacked = [];
for (var i=1; i <= lastRow; i++){
var cell = mySheet.getRange(i, checkColumn);
if(cell.isBlank()){
Logger.log(i + "is not yet notified");
unslacked.push(i);
}
}
Logger.log("unslcked yet"+unslacked)
for (var i=unslacked[0]; i <= unslacked[unslacked.length - 1]; i++){
var pdfCell = mySheet.getRange(extention_column+i)
var checkSlack = mySheet.getRange(slack_column+i)
Logger.log(checkSlack.isBlank())
Logger.log(pdfCell.getValue())
if (pdfCell.getValue() == "pdf" && checkSlack.isBlank() == true)
{
var requestId = mySheet.getRange(request_column+i).getValue();
var clientId = mySheet.getRange(client_column+i).getValue();
var claimId = mySheet.getRange(claim_column+i).getValue();
var groupId = mySheet.getRange(group_column+i).getValue();
Logger.log(groupId)
if (branches.includes(groupId)){
var message = "\nrequestId:" + requestId + "\nclientId:" + clientId + "\nclaimId:" + claimId
var postUrl = slack_channel
var username = 'botbot';
var icon = ':hatching_chick:';
var jsonData =
{
"username" : username,
"icon_emoji": icon,
"text" : message,
link_names: 1
};
var payload = JSON.stringify(jsonData);
var options =
{
"method" : "post",
"contentType" : "application/json",
"payload" : payload
};
UrlFetchApp.fetch(postUrl, options);
checkSlack.setValue(true);
}
}
}
}
Apps Script triggers are bound project-based, not script filed based
If you have multiple functions with the same name in your project - there is no way to know to which one the trigger becomes bound.
Most likely your 5 onChange triggers are all bound to the same function and thus the function is executed multiple times (sending multiple Slack notifications as a result)
It does not make a difference if the functions are located within the same script file or within different script files within the same project
Splitting up your code into different code files is only for visibility/structure purposes, for the trigger the functions are still located all within the same project
Solution
Remove from your project all existing triggers that are bound to functions with not unique names
Give to all functions in your project (not just script file) unique names and save all script files
Install new triggers either programmatically or manually
Now you can be sure that each trigger is bound to a different function
Mind that if the content of your functions is the same (e.g. containing request to send Slack notifications), this content will be executed the same amount of times as the number of respective triggers in your project, so if the content of your functions is identical, you actually need to keep only one function bound to one trigger and remove all the functions of identic content.

How do I get my discord bot to send a random meme/picture

How do I get my bot to send a random picture/meme in discord. I'm using discord.js and this is as far as I got.
if (msg.content === '-meme');
var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]} , {files:["https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});
var fact = Math.floor(Math.random() * randommeme.length);
msg.channel.send('goat meme', randommeme[fact]);
});
This should send a random picture but when I run the command it only says "goat meme". I tried this code before and it worked.
client.on('message', msg => {
if (msg.content === '+meme') {
msg.channel.send("This is a good fluffy goat", {files: ["https://cdn.discordapp.com/attachments/757397429107556422/816234172737126430/A_good_fluffy_goat.png","https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]});
}
});
I really don't know what Im doing wrong here?
First create an array of links, and then use the random function to get a random link from the array.
const meme = ['link_1','link_2','link_3','link_4'];
const index = Math.floor(Math.random() * meme.length);
message.channel.send('Goat meme',{files:[meme[index]]});
where link_1, link_2 etc. are attachment file URL.
There's a typo in line two, the right code should be this:
var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png", "https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});

d3.json() won't execute. keeps getting error: 400

I'm creating a dummy JSON value and is trying to show them but the problem is i keep getting this error:
My code snippet is below:
var jsonData = '[{"id":"31370100","machine_name":"GUMACA BRANCH CAM","machine_type":"CAM","operation_start":"05:04:33","operation_end":"09:04:33"}]'
d3.json(jsonData).then((data)=>{
console.log(data);
});
d3.json takes a URL as the parameter. As you have the JSON already, you probably just need JSON.parse(), and there is no need to use d3 in this instance. So your code would look something like:
var jsonData = '[{"id":"31370100","machine_name":"GUMACA BRANCH CAM","machine_type":"CAM","operation_start":"05:04:33","operation_end":"09:04:33"}]'
let data = JSON.parse(jsonData);
console.log(data);

Access GlideRecord from within service portal widget

How can I run a Glide query from in a widget? (Service Portal)
This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232"); // hardcoded good sample
destination_sys_id = grTask.sys_id;
When I run the code in Scripts, I get:
*** Script: sys_id: 0f4d[...]905
When I run it in the widget, I get:{}
To elaborate on my Widget code:
Body HTML template
data.destination_sys_id = {{data.destination_sys_id }}
Server script
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id;
data.destination_sys_id = destination_sys_id;
})()
you can add it as c.data.destination_sys_id nad at the time of assigning the value to object always use .toString() in order to stringify the field value.
I needed a .toString(); in my server script:
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id.toString(); // <- note the addition of .toString()
data.destination_sys_id = destination_sys_id;
})()
Another way is to use grTask.getUniqueValue() instead of grTask.sys_id.toString().
Also, getters and setters are recommended with GlideRecord, so use grTask.getValue('sys_id') instead of grTask.sys_id.toString().

ReferenceError: "BarSeriesImpl" is not defined

My report works fine in BIRT- it shows some Bar chart graphic.
But when I import in some system (IBM maximo) I am getting this error instead of displaying the bar chart:
ReferenceError: "BarSeriesImpl" is not defined. at line 8 of chart script:''
I used this script to show me some values on Bar chart.
importPackage( Packages.java.util );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getClass() == BarSeriesImpl ){
var inv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("IN"));
var outv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("OUT"));
var canv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("CANCELED"));
var narray1 = new ArrayList( );
narray1.add(inv);
narray1.add(outv);
narray1.add(canv);
dataSet.setValues(narray1);
}else{
var catArray = new ArrayList();
catArray.add("IN");
catArray.add("OUT");
catArray.add("CANCELED");
dataSet.setValues(catArray);
}
}
How to solve this? Does I have to import somehow this class in my system or ..?
Thank you
I know I'm resurrecting an old question but this just caught my eye because it was similar to another post I answered this week. I think you might be missing org.eclipse.birt.chart.model.type.impl.BarSeriesImp in the systems that you are getting this error message. I think if you add the BIRT runtime jars to the lib path then it should resolve that error.

Resources