How can I make the command work on page specific - css

Thank you in advance for your help. How can I make the following command work only on the page named "customer" and not on other pages?
function onEdit(e) {
if (e.range.columnStart > 9)
return;
e.source.getActiveSheet().getRange(e.range.rowStart, 12).setValue(new Date());
}

If you want that code to run only inside a given page, you should include that code only in that page.
But in case you have a general js that you are going to include anywhere and you want to add logic to it so that it can make guesses on which page is loaded when it's running, you can read the value of window.location.href that will return the entire url of the page currently loaded in viewport:
var isCurrentPageCustomer = false;
//this regex will extract the final part of the url after the last slash (/)
//so if the url was http://mydomain/path/to/page the match will look for /page
var match = /\/([^/]+)$/.exec(window.location.href);
if (match != null) {
//result is holding "page" without the trailing slash (/)
result = match[1];
//if that part (eg.: 'page') matches 'customer', switch the flag=true
if (result === 'customer') isCurrentPageCustomer = true;
}
if(isCurrentPageCustomer)
console.log('current page is customer.');
else
console.log('current page is NOT customer.');
But it turned out later that you meant to run some code only when the current active sheet (in Google Sheets) is named customer. In that case I just changed your onEdit handler function and used the property name of the active sheet to decide to return from the function instantly if it doesn't match with 'customer'
function onEdit(e){
//if the name of the active sheet is not 'customer'
if (e.source.getActiveSheet().getName() != 'customer')
//exits the function without executing the rest of its code
return;
//the rest of your code here
}

Related

if URL contains function in puppeteer

So I am trying to have my code do something if the URL contains this: https://kith.com/throttle/queue?
After the '?' there can be anything, so I only want it to identify 'https://kith.com/throttle/queue?'
I am using puppeteer and want it to work like this:
If the URL contains 'https://kith.com/throttle/queue?' then wait until it passes the queue (page.waitForNavigation({ waitUntil: 'networkidle2' }) would work for waiting until it's through the queue
Else (If the URL doesn't contain that): do nothing and go to the next line of code
It is hard to understand how do you get this URL, but if this is a URL of a current page, you can try this:
const url = await page.evaluate(() => location.href);
if(url.startsWith('https://kith.com/throttle/queue?')) {
// Wait for navigation.
} else {
// Do nothing.
}

Conditional Search Results

I'm creating a 'Kiosk' where users can sign-in and out.
I'm stuck on the sign-out component.
I'd like to have a table that only returns visitors that have not signed out after the end-user searches.
My search box has the following properties:
Value:
#datasource.query.filters.fullname._startsWith
On value change:
if (widget.value === null || (widget.value).length === 0){
widget.datasource.unload();
} else {
widget.datasource.load();
}
I'm new to this & JS as a whole. How can I filter the search to only contain users that have not signed out?
As suggested in the comments you need to add widget.datasource.query.filters.signedout._equals = false; line before you load your data source. However you should make one more change while unloading.
Here's the full code.
if (widget.value === null || (widget.value).length === 0){
widget.datasource.unload();
widget.datasource.load();
} else {
widget.datasource.unload();
widget.datasource.query.filters.signedout._equals = false;
widget.datasource.load();
}
Here unload() will unload previous data and load() will reload it. Now while reloading you can pass multiple filters so it reloads only filtered records.

Trigger a button click from a URL

We need to scrape VEEC Website for the total number once a week.
As an example, for the week of 17/10/2016 - 23/10/2016 the URL returns the number Total 167,356 when the search button is clicked. We want this number to be stored in our database.
I'm using coldfusion to generate the weekly dates as params and have been passing them like the above URL. But I'm unable to find a query param so that the "Search" button click event is triggered.
I've tried like this & this but nothing seems to be working.
Any pointers?
It seems like for every form submission, a CRSF token is added, which prevents malicious activity. To make matters worse for you, the CRSF token is changed for each form submission, not just for each user, which makes it virtually impossible to circumvent.
When I make a CFHTTP POST request to this form, I get HTML FileContent back, but there is no DB data within the results table cell placeholders. It seems to me that the form owner allows form submission from an HTTP request, but if the CRSF token cannot be validated, no DB data is returned.
It maybe worth asking the website owner, if there is any kind of REST API, that you can hook into...
If you want to use a headless browser PhantomJS (https://en.wikipedia.org/wiki/PhantomJS) for this, here is a script that will save the total to a text file.
At command prompt, after you install PhantomJS, run phantomjs.exe main.js.
main.js
"use strict";
var firstLoad = true;
var url = 'https://www.veet.vic.gov.au/Public/PublicRegister/Search.aspx?CreatedFrom=17%2F10%2F2016&CreatedTo=23%2F10%2F2016';
var page = require("webpage").create();
page.viewportSize = {
width: 1280,
height: 800
};
page.onCallback = function (result) {
var fs = require('fs');
fs.write('veet.txt', result, 'w');
};
page.onLoadStarted = function () {
console.log("page.onLoadStarted, firstLoad", firstLoad);
};
page.onLoadFinished = function () {
console.log("page.onLoadFinished, firstLoad", firstLoad);
if (firstLoad) {
firstLoad = false;
page.evaluate(function () {
var event = document.createEvent("MouseEvents");
event.initEvent("click", true, true);
document.querySelectorAll(".dx-vam")[3].dispatchEvent(event);
});
} else {
page.evaluate(function () {
var element = document.querySelectorAll('.dxgv')[130];
window.callPhantom(element.textContent);
});
setTimeout(function () {
page.render('veet.png');
phantom.exit();
}, 3000);
}
};
page.open(url);
The script is not perfect, you can work on it if you're interested, but as is it will save the total to a file veet.txt and also save a screenshot veet.png.

Sage CRM - Loading a screen with a entity data?

Given this code:
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
Container.AddBlock(CustomCommunicationDetailBox);
if(!Defined(Request.Form)){
CRM.Mode=Edit;
}else{
CRM.Mode=Save;
}
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);
Im calling this .asp page with this parameters but does not seems to work
popupscreeens.asp?SID=33185868154102&Key0=1&Key1=68&Key2=82&J=syncromurano%2Ftabs%2FCompany%2FCalendarioCitas%2Fcalendariocitas.asp&T=Company&Capt=Calendario%2Bcitas&CLk=T&PopupWin=Y&Key6=1443Act=512
Note the Key6=Comm_Id and Act=512??? which i believe it is when editing?
How can i achieve to fill the screen's field with entity dada?
In this case it is a communication entity
In order to populate a custom screen with data, you need to pass the data to the screen.
First, you need to get the Id value. In this case, we're getting it from the URL:
var CommId = Request.QueryString("Key6") + '';
We're going to put a few other checks in though. These are mainly to handle scenarios that have come up in different versions or from different user actions.
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
Certain user actions can make the URL hold multiple Ids in the same attribute. In these cases, those Ids are separated by commas. So, if the Id is not defined, we check if there is a comma in it. If there is, we take the 1st Id.
After we have the Id, we need to load the record. At this point, you should have already checked you have a valid id (E.g. not zero) and put some error handling in. In some pages you may want to display an error, in others you may want to create a new, blank record. This gets the record:
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
After that, you need to apply the record to the screen. Using your example above:
CustomCommunicationDetailBox.ArgObj = CommRecord;
Adding all that to your script, you get:
var CommId = Request.QueryString("Key6") + '';
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
// add some error checking here
// get the communication record
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
// get the container and the detail box
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
// apply the communication record to the detail box
CustomCommunicationDetailBox.ArgObj = CommRecord;
// add the box to the container
Container.AddBlock(CustomCommunicationDetailBox);
// set the moder
if(!Defined(Request.Form)){
CRM.Mode=Edit;
} else {
CRM.Mode=Save;
}
// output
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);
However, we would advise putting in more error/exception handling. If the user is saving the record, you will also need to add a redirect in after the page is written.
Six Ticks Support

Angular.js $http $window.location and global variables

I'm trying to update a global variable within an $http request, redirect to a new page and then print that variable (on error). I'm not sure if i'm doing this correctly, but when I try to print my variable ($rootscope.adHocLevel2) it remains empty.
In js file
$scope.searchStep2 = function(option) {
$http.post($scope.url, { "option" : option}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$rootScope.response = data;
})
.
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
$rootScope.response = 'Request failed';
$rootScope.routeAd = {"route": "../adHoc/adhoc.html"};
$rootScope.addHocLevel2 = {"suggestedCategory": "Car","suggestedLocLabel": "world","suggestedShadowURL": "http://www.toyota.com/auris/hybrid"};
$window.location=$rootScope.routeAd.route;
});
};
In Html I'm trying to print
<input type="text" ng-model="optLocation" value={{addHocLevel2}} />
Thanks ahead
Based on the above code, you have $window.location = $rootScope.routeAd.route which points to "../adHoc/adhoc.html". This will reload the app and therefore you lose addHocLevel2 value.
You will need to redirect to its hash route path (e.g. #/adhoc) - as per your routeProvider.when("/adhoc") config, rather than ../adHoc/adhoc.html.
Also I think the best way when moving within the angular's one page app is to use $location.path(yourRoutePath) rather than $window.location unless you want to change location entirely (new URL somewhere).
e.g
You have 2 routes setup:
app.config(function($routeProvider){
$routeProvider
.when('/main', { templateUrl:'/main/main.html',controller:'MainCtrl'})
.when('/adhoc', { templateUrl: '/adHoc/adhoc.html',controller:'AdHocCtrl});
}
Then say you want to redirect from /main to /adhoc, it goes something like this:
app.controller('MainCtrl',function($rootScope,$scope,$location,$http){
$http.post(...).error(function(data,status){
$rootScope.addHocLevel2 = {...};
$location.path("/adhoc"); // this will 'redirect' you to adHoc/adhoc.html page
}
})
Update: I updated your plunker: http://embed.plnkr.co/01lfzd4Q4bFoSPAB4WIF/
This is how I would do it - I'm sure there are another approaches. I use index.html as the template and have main.html and adhoc.html as the 2 other pages that you can switch to based on the URL.

Resources