I am trying to delete rows in DE (shared DE). The code I am using is
<html>
<head>
<title>test12</title>
</head>
<body>
<script runat="server">
Platform.Load("core", "1.1.1");
try{
var deleteCount = DeleteData("Voucher_Notification_Threshold","return", 1)
}catch(ex)
{
Write(Stringify(ex));
}finally
{
Write(Stringify(deleteCount));
}
</script>
</body>
</html>
My code (ones is complete and running) will be running as script in automation . For now i am testing it , thus i have put it cloudpages . This cloud page is also in enterprise BU and so is the Data extension from which i want to delete
I get following error :
{"message":"Object expected: DeleteData","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(VariableDeclarationStatement statement)\r\n at Jint.Expressions.VariableDeclarationStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: DeleteData\r\nException of type 'Jint.Native.JsException' was thrown. - from Jint\r\n\r\n"}
any clue was is causing the issue .
first please use StackExchange for more reactivity on SFMC stuff.
The parameters of DeleteData function include brackets on two last parameters.
<script runat="server">
Platform.Load("core", "1.1.1");
try{
var deleteCount = DeleteData("Voucher_Notification_Threshold",["return"], [1])
}catch(ex)
{
Write(Stringify(ex));
}
</script>
Try this -
<script runat="server">
Platform.Load("core", "1.1.1");
var DE = DataExtension.Init("Voucher_Notification_Threshold");
DE.Rows.Remove(["return"],[1]);
</script>
Related
I'm currently working on a project where I want to display a locally stored SVF-File in the browser using the Forge Viewer. I have already tried different approaches but none of them seem to work and I run into different exceptions every time.
Here is how I try to do it using React and Typescript.
This is the App.tsx where I load the Viewer Component:
<div className="col-sm-8 fill">
<ForgeViewer />
</div>
This is my Viewer Component:
import React from 'react';
import {useEffect} from 'react'
import {initializeViewer} from './viewer-helper';
const ForgeViewer: React.FC = () => {
useEffect(() => {
initializeViewer()
}, [])
return (
<div>
<div id="forgeviewer"></div>
</div>
);
}
export default ForgeViewer
And this is the helper that I wrote for my Viewer Component:
const options : Autodesk.Viewing.InitializerOptions = {
doc: './models/small-revit-sample-house/Resource/3D_View/_3D_/_3D_.svf',
env: "Local",
}
export const initializeViewer = () => {
let container: HTMLElement | null;
let viewer: Autodesk.Viewing.GuiViewer3D;
container = document.getElementById('forgeviewer');
if(container !== null){
viewer = new Autodesk.Viewing.GuiViewer3D(container);
}
Autodesk.Viewing.Initializer(options, function () {
//viewer.loadDocumentNode(options.doc, "/public/manifest.json");
//viewer.loadModel(options.doc, onDocumentLoadSuccess, onDocumentLoadFailure);
//Autodesk.Viewing.Document.load(modelURL, onDocumentLoadSuccess, onDocumentLoadFailure);
viewer.start(options.doc);
//loadViewer(modelURL);
});
}
As you can see, I have already tried different approaches but none of them seem to work.
1: Using the viewer.start function I get -> "Error while processing SVF: End of Central Directory Record not found"
2: Using the viewer.loadDocumentNode i get -> "Unhandled Rejection (TypeError): e.getViewableUrn is not a function"
3: Using the viewer.loadModel i get -> "Uncaught (in promise) TypeError: te is undefined" Btw. the function onDocumentLoadSuccess is an empty function that doesnt get called.
I would be really happy if I could just get on of these ways to work and understand more of whats going on. :)
You can load SVFs from custom locations using either the start method or the loadModel method:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.css" type="text/css">
<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
}
#preview {
height: 100%;
}
</style>
<title>Autodesk Forge: Local SVF</title>
</head>
<body>
<div id="preview"></div>
<script>
const MODEL_URL = 'https://petrbroz.s3-us-west-1.amazonaws.com/svf-samples/sports-car/0.svf';
Autodesk.Viewing.Initializer({ env: 'Local' }, async function () {
const viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('preview'));
viewer.start(MODEL_URL);
// viewer.loadModel(MODEL_URL);
});
</script>
</body>
</html>
It's possible that the error you're getting is related to the React wrapper instead.
I got it to work. Here is how I did it: The models-folder is now located inside the public folder (Bad for secruity but doesnt matter for my project). Than you can load the svf file like this:
Autodesk.Viewing.Initializer(options, function () {
viewer.start( "./models/path/file.svf");
});
We have 2 configuration files: one is in our Spring Boot application (application.properties) and another in our ReactJs app (we use .env in create-react-app). It was decided to use Spring Boot application.properties also in ReactJs app. Can anyone please guide me how can I achieve this?
I have read about "properties-reader" and tried to use it, but I don't have webpack.config.js file in our ReactJs app.
Thymeleaf provides the easiest way to pass data from application.properties file to Javascript via the template (index.html) file.
Alternatively, it can be done using normal JSP also.
Here are the working examples:
Option 1: Thymeleaf
Step 1: Define the interesting data attributes as hidden elements in the index.html file
<div id="root"></div> ---> Div to be updated by react
....
<span id="myData" hidden></span>
<!-- Script to set variables through Thymeleaf -->
<script th:inline="javascript">
var myData = "[${myData}]]";
document.getElementById("myData").innerHTML = myData;
</script>
Important note:
Make sure that the same index.html file exists in the '/public' folder of Reactjs project as well as in the /src/main/resources/templates/ folder of the spring boot project.
Step 2: Use model.addAttribute() method in Spring Boot to invoke Thymeleaf for setting data in the index.html file
#GetMapping("/")
public String index(Model model) {
// Get the value of my.data from application.properties file
#Value("${my.data}")
private String myData;
// Call Thymeleaf to set the data value in the .html file
model.addAttribute("myData", myData);
return "index";
}
Step 3: Update the ReactJS code to read the interesting attribute using document.getElementById
let myData = document.getElementById("myData").innerHTML
More information:
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#javascript-inlining
https://attacomsian.com/blog/thymeleaf-set-javascript-variable
Option 2: JSP
Step 1: Define the interesting data attributes as hidden elements in the index.jsp file
Location of index.jsp: src/main/webapp/WEB-INF/jsp/index.jsp
<!DOCTYPE html>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
<!-- Head section here -->
</head>
<body>
<!-- Div to be updated by react -->
<div id="root">
</div>
<!-- Include the interesting attribute as a hidden field -->
<span id="myData" hidden>${myData}</span>
</body>
</html>
Important note:
Make sure that the /public/index.html file of reactjs project has the same content (<body>...</body>) as that of the src/main/webapp/WEB-INF/jsp/index.jsp file of spring boot project)
Step 2: Use map.put() in Spring Boot controller to update data in JSP
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
#Controller
public class HomePageController{
// Read data from application.properties
#Value("${my.data}")
private String myData;
// Update data attributes of JSP using map.put
#GetMapping("/")
public String index( Map<String, Object> map ) {
map.put("myData", myData);
return "index";
}
}
Step 3: Update the ReactJS code to read the interesting attribute using document.getElementById
let myData = document.getElementById("myData").innerHTML
More information:
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/
I'am trying to use the CefSharp.Wpf NuGet package (v79.1.360) to display a simple html web page from disk.
The page has dependencies to local files (javascript, css, etc. ...) in a different directory than the page itself.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="file:///G:/AngularJS/Framework/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="MyApp.css">
<script src="file:///G:/AngularJS/Framework/angular.min.js"></script>
<script src="file:///G:/AngularJS/Framework/jquery.min.js"></script>
<script src="file:///G:/AngularJS/Framework/bootstrap.min.js"></script>
<script src="MyApp.js"></script>
<title></title>
</head>
<body>
<p class="font-weight-bold">Select address</p>
<table class="table table-hover">
<thead>
<tr class="bg-primary">
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Code</th>
<th scope="col">City</th>
<th scope="col">Street</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="address in Model.AddressList"
ng-click="Model.PickRow(address)"
ng-style="{'background-color': address.Background}">
<td>{{address.Id}}</td>
<td>{{address.Name}}</td>
<td>{{address.PostalCode}}</td>
<td>{{address.City}}</td>
<td>{{address.Street}}</td>
</tr>
</tbody>
</table>
</body>
</html>
I'm able to display the page on a chromium based web browser (Firefox) with modified settings:
security.fileuri.strict_origin_policy false
-> Firefox isn't a chromium based web browser, so I tested it with google chrome and it worked too.
On my web research I found this post related to the issue (unfortunately this post is from 2014):
https://github.com/cefsharp/CefSharp/issues/572
So I tried to set the browser settings for the cef sharp control:
<Window x:Class="WebControl.MyWebBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cefSharpCore="clr-namespace:CefSharp;assembly=CefSharp.Core"
xmlns:cefSharpWpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
Height="300" Width="300">
<Grid>
<cefSharpWpf:ChromiumWebBrowser>
<cefSharpWpf:ChromiumWebBrowser.BrowserSettings>
<cefSharpCore:BrowserSettings WebSecurity="Disabled"
FileAccessFromFileUrls="Enabled"
UniversalAccessFromFileUrls="Enabled"/>
</cefSharpWpf:ChromiumWebBrowser.BrowserSettings>
</cefSharpWpf:ChromiumWebBrowser>
</Grid>
</Window>
But this doesn't work. I also tried to set the settings in the code behind file without success.
Long story short:
Current result
Expected result
If someone has a solution please let me know.
Thanks in advance for reading the post :-)
Thanks to amaitland for leading me to the right direction:
I strongly advise against using file:/// when loading from local disk. Different security restrictions apply and there are many limitations. I'd suggest using a Scheme handler or implementing your own IResourceRequestHandlerFactory. (Loading a data: encoded URI is also pretty handy, specially for the OffScreen project).
If you choose to ignore this advice you'll have to resolve any issues you have using file:/// yourself. ceforum is the best resource.
Copied from: https://github.com/cefsharp/CefSharp/wiki/General-Usage#file-uri-file
The solution is to create a custom scheme handler:
https://github.com/cefsharp/CefSharp/wiki/General-Usage#scheme-handler
1) I addeded angular, bootstrap and jquery files as resources to my visual studio project.
2) I created DiskSchemeHandlerFactory.cs:
public class DiskSchemeHandlerFactory : ISchemeHandlerFactory
{
private static readonly string _SchemeName = "disk";
private static readonly IDictionary<string, string> _ResourceDictionary;
public string SchemeName
{
get { return _SchemeName; }
}
static DiskSchemeHandlerFactory()
{
_ResourceDictionary = new Dictionary<string, string>
{
{ "/angular.min.js", Properties.Resources.angular_min },
{ "/angular.min.js.map", Properties.Resources.angular_min_js },
{ "/bootstrap.min.js", Properties.Resources.bootstrap_min1 },
{ "/bootstrap.min.css", Properties.Resources.bootstrap_min },
{ "/jquery.min.js", Properties.Resources.jquery_min }
};
}
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
{
//Notes:
// - The 'host' portion is entirely ignored by this scheme handler.
// - If you register a ISchemeHandlerFactory for http/https schemes you should also specify a domain name
// - Avoid doing lots of processing in this method as it will affect performance.
// - Uses the Default ResourceHandler implementation
var uri = new Uri(request.Url);
var fileName = uri.AbsolutePath;
string resource;
if (_ResourceDictionary.TryGetValue(fileName, out resource) && !string.IsNullOrEmpty(resource))
{
var fileExtension = Path.GetExtension(fileName);
return ResourceHandler.FromString(resource, fileExtension);
}
return null;
}
}
3) I modified the static constructor of MyWebBrowser.xaml.cs:
static MyWebBrowser()
{
if (Cef.IsInitialized == false)
{
var diskSchemeHandlerFactory = new DiskSchemeHandlerFactory();
var settings = new CefSettings();
settings.RegisterScheme(new CefCustomScheme()
{
SchemeName = diskSchemeHandlerFactory.SchemeName,
SchemeHandlerFactory = diskSchemeHandlerFactory
});
Cef.Initialize(settings);
}
}
4) Finally I changed the file paths of the html page:
<script src="disk://angular/angular.min.js"></script>
<script src="disk://jquery/jquery.min.js"></script>
<script src="disk://bootstrap/bootstrap.min.js"></script>
Maybe I modify it to work with full file paths too. With this solution I have to compile my project each time I want to use another file...
I am currently working on a web application using React, TypeScript and Webpack. I want Webpack to generate images URLs according to a subdomain that I only know on runtime and not during the compile time.
I've read this on Webpacks's documentation:
http://webpack.github.io/docs/configuration.html#output-publicpath
Note: In cases when the eventual publicPath of of output files isn’t known at compile time, it can be left blank and set dynamically at runtime in the entry point file. If you don’t know the publicPath while compiling you can omit it and set webpack_public_path on your entry point.
webpack_public_path = myRuntimePublicPath
// rest of your application entry
But I can't get it working.
I've set the webpack_public_path variable in my app entry point. But how can I use its value in my Webpack config?
I need to use it here:
"module": {
"rules": [
{
"test": /.(png|jpg|gif)(\?[\s\S]+)?$/,
"loaders": [url?limit=8192&name=/images/[hash].[ext]]
}
]
}
I need to do something like this:
"loaders": ['url?limit=8192&name=__webpack_public_path__/images/[hash].[ext]']
ANSWER
I've managed to make it work. So in my entry point file (start.tsx), I declare de __webpack_public_path__ free var before the imports and I assign its value after the imports.
/// <reference path="./definitions/definitions.d.ts" />
declare let __webpack_public_path__;
import './styles/main.scss';
/* tslint:disable:no-unused-variable */
import * as React from 'react';
/* tslint:enable:no-unused-variable */
import * as ReactDOM from 'react-dom';
import * as Redux from 'redux';
import { Root } from './components/root';
__webpack_public_path__ = `/xxxx/dist/`;
Now, the public path is being used when I have an img tag:
<img src={require('../../images/logo.png')} />
Turns into:
<img src='/xxxx/dist/images/125665qsd64134fqsf.png')} />
Here's my basic setup in terms of the generated HTML:
<script>
window.resourceBaseUrl = 'server-generated-path';
</script>
<script src="path-to-bundle" charset="utf-8"></script>
My main entry point script:
__webpack_public_path__ = window.resourceBaseUrl;
In my case, it was the order I was loading my scripts in my index.html. Ensure the last <script> tag in your index.html has a src attribute.
I discovered this by reading through the generated webpack code:
var scriptUrl;
if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
var document = __webpack_require__.g.document;
if (!scriptUrl && document) {
if (document.currentScript)
scriptUrl = document.currentScript.src
if (!scriptUrl) {
var scripts = document.getElementsByTagName("script");
if(scripts.length) scriptUrl = scripts[scripts.length - 1].src
}
}
// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
__webpack_require__.p = scriptUrl;
It just looks through your scripts and picks the last one to set as the scriptUrl which it then uses to figure out if you are using a "publicPath" or not. Since my last script did not have a src attribute, all changes to __webpack_public_path__ or webpack.config.js { ..., output: { publicPath: "" }} were being ignored.
My original index.html:
<body>
<div id="root">
${html}
</div>
<script src="/static/runtime.js" type="module"></script>
<script src="/static/polyfills.js" type="module"></script>
<script src="/static/vendor.js" type="module"></script>
<!-- the below is the offending script -->
<script>
// WARNING: See the following for security issues around embedding JSON in HTML:
// https://redux.js.org/usage/server-rendering#security-considerations
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(
/</g,
'\\u003c'
)}
</script>
</body>
My index.html after my changes:
<body>
<div id="root">
${html}
</div>
<script>
// WARNING: See the following for security issues around embedding JSON in HTML:
// https://redux.js.org/usage/server-rendering#security-considerations
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(
/</g,
'\\u003c'
)}
</script>
<script src="/static/runtime.js" type="module"></script>
<script src="/static/polyfills.js" type="module"></script>
<script src="/static/vendor.js" type="module"></script>
</body>
This took me several days to fix.
Not a big webpack expert, but I'm not sure you are using that loader in the right way. The url-loader is there to help you load files data that are required/imported in your code.
So if in your entry point you write something like:
var imageData = require("path/to/my/file/file.png");
Webpack will see that you are trying to import something different than a .js file and then will search in your configured loader list, to see if it can use any loader to load that resource.
Since you had set up a loader whith a test property that matches your required resource type (extension .png), it will use that configured loader (url-loader) to try loading that resource into your bundle.
You can also tell webpack what loader he needs to use by prepending the loader (and some query strings if you wish) in the require path:
var imageData = require("url-loader?mimetype=image/png!path/to/my/file/file.png");
Also, I'm not sure there is even a name parameter you can pass to the url-loader.
I'm using PHP Framework CakePHP 3.0.3 and would like to know how to insert the keywords defer and async script tags:
How is the Script Injection with the framework:
<? = $ This-> html-> script ('jquery-1.11.1.min.js')?>
How is rendered:
<script src = "/ js / jquery-1.11.1.min.js"> </ script>
Like how you would like it to be:
<async script src = "/ js / jquery-1.11.1.min.js"> </ script>
<script defer src = "/ js / jquery-1.11.1.min.js"> </ script>
In the documentation I saw nothing that could be done this insert.
An alternate form is to make as follows:
<? = $ This-> html-> script ('jquery-1.11.1.min.js' ['defer' => true])?>
and this rendering:
<script src = "/ js / jquery-1.11.1.min.js" defer = "defer"> </ script>
This one works for me.
<?= $this->html->script('jquery-1.11.1.min.js', ['async']);?>
After
<script src="/js/jquery-1.11.1.min.js" async="async"></script>
It's impossible to do it with $this->Html->script() function. This is hard coded in Cake\View\StringTemplate. I suggest to just leave it as it is now, it will work anyway.
If it's vital issue for you try override HtmlHelper and implement your own script() function.