Dynamic placeHolders - modx

I would like ask, if anyone knows how can I make a dynamic placeholders using an array. Basically I have this structure, and need to create a placeholders where the "name" has the "content"
{
"name": "bigTitle",
"type": "text",
"content": "Got a question?"
}
return placeholders with the content

Please use toPlaceholders method here, use can create own custom snippet/plugin (depends on how do you really use it) and run this this method inside.

Related

Fail to give reference to another JSON schema

I am new in JSON schema and trying to validate my request with JSON schema. So i created schema. But i don't know why i am not able to give refrence to any another schema which located in same folder can any one help me to how to give $ref
{
"$id":"file:/schemas/ActionType",
"title":"ActionType",
"type":"object",
"properties":{
"ActionType":{
"enum":["fullLoad","update","insert","delete"]
}
},
"additionalProperties": false,
"required": ["ActionType"]
}
{
"$id":"file:/schemas/ERoaming",
"title":"ERoaming",
"type":"object",
"properties":{
"ActionType":{
"type":"object",
"$ref":"/schemas/ActionType.json"
}
},
"additionalProperties": false,
"required": ["ActionType"],
"$defs": {
}
}
I tried with without $id, relative path, path.
First of all, I don't think that's a valid file URI. It should look like file:///path/to/schemas/ActionType with three /s after the : and the full system path. You can't use a relative path.
Otherwise, everything looks fine with the schema. Another likely problem is that not all JSON Schema libraries understand files that reference the file system. You'll want to make sure the one you're using supports that feature.
When you're working with schemas in files, it's unnecessary to use $id. If the library properly handles file system references, the full path and filename should be automatically be used as the schema identifier. Then you can use relative references like I'm sure you're familiar with, { "$ref": "./ActionType.json" }.

Azure ARM Template - conditional input parameter

In Short:
Is it possible to have condition field (or something else to achieve this functionality), inside a parameter, so that this parameter input will be asked to the user, only based on another parameter's value.
i.e., Only if user selects Create New on a parameter, the input for the name of that parameter should be asked.
In Detail:
I have a parameter virtualNetworkCreateNewOrUseExisting which will accept two values - Create New and Use Existing.
"parameters": {
"virtualNetworkCreateNewOrUseExisting": {
"type": "string",
"defaultValue": "Create New",
"allowedValues": [
"Create New",
"Use Existing"
]
},
// Other parameters
}
I am trying to create a Virtual Network based on an input from user.
If user selects Create New, it will be created, and if they select Use Existing, it will be skipped. I see that this is achievable by using condition field inside the resource.
"resources": [
{
"condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
// Other fields
}
// Other resources
]
Now, my question here is that,
Similar to this, is it possible to have condition field, inside another parameter, so that this parameter input will be asked to the user, only based on the previous parameter value.
i.e., Only if user selects Create New, the input for Virtual Network Name should be asked.
Something like this, by using a condition field:
"parameters": {
"virtualNetworksName": {
"condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
"defaultValue": "vn-1",
"type": "string"
},
// Other parameters
}
But, I see that condition field, is not supported inside parameters (at least as of now).
Or, is it at least possible to have, if statements, like this (So that, the value of the field will be displayed empty by default if user selects Use Existing.):
"parameters": {
"virtualNetworksName": {
"defaultValue": "[if(equals(parameters('virtualNetworkCreateNewOrUseExisting'),'Create New'), 'vn-1', '')]",
"type": "string"
},
// Other parameters
}
Or, any other way to achieve this goal?
You can't do this natively in the template file, but in the portal user experiences for deploying the template you can... See:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-create-portal-forms
and
https://learn.microsoft.com/en-us/azure/azure-resource-manager/managed-applications/create-uidefinition-overview
You don't have to use a templateSpec or managedApp (see the "Deploy to Azure button here: https://github.com/Azure/azure-quickstart-templates/tree/master/demos/100-marketplace-sample )
but templateSpec or managedApp will give you a better experience if that's an option.
As per the current Azure documentation, we cannot add conditions to parameters in parameters block.
As a side note you can use PowerShell parameter inline functions while deploying the template.
We see that there is a feature request already in place to add Support functions within the definition of parameters... ยท Community (azure.com) We would suggest you to make a comment & Upvote on the exiting feedback request .

Azure Logic Apps - Moving Email Message with Move Message action

I'm fairly new to Logic Apps and I have an app that I'm trying to get to move an email to a subfolder of the Inbox in a shared mailbox, but I'm trying to generate the path based on the date and I cannot for the life of me get it to work. I don't know if my path syntax is wrong or what.
The subfolder structure is basically
- Inbox
- 2018
- Jan
- Feb
- Mar
- Etc
And I'm trying to generate the path based off the year and the month using the Expressions part of a field. I've got an expression that generates the path for me
concat('Inbox\',formatDateTime(convertFromUtc(utcNow(),'Mountain Standard Time'),'MMM'),'\',formatDateTime(convertFromUtc(utcNow(),'Mountain Standard Time'),'yyyy'))
When the logic app runs this generates the correct path string of Inbox\2018\Jan but when the Move Email action runs it always escapes the backslash and then says it can't find the folder Inbox\\2018\\Jan.
So I either have this format wrong, I can't put the email in a subfolder or there's another way to do this.
I tried using the folder picker to pick one of the month subfolders and then peeked at the code and it uses some base64 encoded string for the path. I've pasted below what the peeked code shows
{
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail/Move/#{encodeURIComponent(triggerBody()?['Id'])}",
"queries": {
"folderPath": "Id::AAMkADRmOTgyMDI1LThkODYtNDMwYy1iYThiLTIzODQwN2Y1OGMzYQAuAAAAAAA6K3dJssnITb8NwkAsBOo7AQBaJ9ZTcg-MSoOEUUjjUdOAAAAD0nvYAAA="
},
"authentication": "#parameters('$authentication')"
},
"metadata": {
"Id::AAMkADRmOTgyMDI1LThkODYtNDMwYy1iYThiLTIzODQwN2Y1OGMzYQAuAAAAAAA6K3dJssnITb8NwkAsBOo7AQBaJ9ZTcg-MSoOEUUjjUdOAAAAD0nvYAAA=": "Jan"
}
}
Does anyone know how I would be able to move an email to a subfolder without using the folder picker?
Edit: Since posting I've also tried using the following strings that also do not work
Inbox/2018/Jan
Inbox:/2018/Jan
/Inbox/2018/Jan
You cant really have the path in terms of a hierarchy folder structure in this particular logic app.
If you look at the Documentation for Office 365 Mail rest operations #
https://msdn.microsoft.com/office/office365/api/mail-rest-operations#MoveCopyMessages
You will notice that to Move messages what you actually need is a folder ID. Also if you look at the logic app Designer, when you select a folder directly from there and then look at the code view you will see an ID. It looks something like
"method": "post",
"path": "/Mail/Move/#{encodeURIComponent(triggerBody()?['Id'])}",
"queries": {
"folderPath": "Id::AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysaQAAA="
}
},
"metadata": {
"Id::AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysaQAAA=": "Jan"
},
The FolderID is unique to every folder. One easy way to find the FolderIDs for a folder is to use
https://developer.microsoft.com/en-us/graph/graph-explorer#
and after signing in , posting
https://graph.microsoft.com/beta/me/mailFolders/Inbox/childFolders
as the query which will give you the ChildFolders for Inbox the values will look something like the following for every folder
"value": [
{
"id": "AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysWPAAA=",
"displayName": "AZCommunity",
"parentFolderId": "AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQDX8XL9o4tkR5vF5sEdh44eAIYnQnhhAAA=",
"childFolderCount": 0,
"unreadItemCount": 5,
"totalItemCount": 169,
"wellKnownName": null
},
For what you are trying to do, you will have to do additional work to map the folders to the folder ID and then assign using that. I would suggest using Azure Functions to easily do this.

How to find an object which is at nth nested level in mongoDB? (single collection, single document)

I am trying to find an nth object using '_id', which is in the same document.
Any suggestions or references or code samples would be appreciated.
(e.g)
Document will look as below:
{
"_id": "xxxxx",
"name": "One",
"pocket": [{
"_id": "xxx123",
"name": "NestedOne",
"pocket": []
}, {
"_id": "xxx1234",
"name": "NestedTwo",
"pocket": [{
"_id": "xxx123456",
"name": "NestedTwoNested",
"pocket": [{"_id": "xxx123666",
"name": "NestedNestedOne",
"pocket": []
}]
}]
}]
}
The pockets shall hold more pockets and it is dynamic.
Here, I would like to search "pocket" using "_id" , say "xxx123456", but without using static reference.
Thanks again.
I highly recommend you change your document structure to something easier to manage/search, as this will only become more of a pain to work with.
Why not use multiple collections, like explained in this answer?
So an easy way to think about this for your situation, which I hope is easier for you to reason about than dropping some schema code...
Store all of your things as children in the same document. Give them unique _ids.
Store all of the contents of their pockets as collections. The collections simply hold all the ids that would normally be inside the pocket (instead of referencing the pockets themselves).
That way, a lot of your work can happen outside of DB calls. You just batch pull out the items you need when you need them, instead of searching nested documents!
However, if you can work with the entire document:
Looks like you want to do a recursive search a certain of number of levels deep. I'll give you a general idea with some pseudocode, in hopes that you'll be able to figure the rest out.
Say your function will be:
function SearchNDeep(obj, n, id){
/**
You want to go down 1 level, to pocket
see if pocket has any things in it. If so:
Check all of the things...for further pockets...
Once you've checked one level of things, increment the counter.
When the counter reaches the right level, you'd want to then see if the object you're checking has a `'_id'` of `id`.
**/
}
That's the general idea. There is a cleaner, recursive way to do this where you call SearchNDeep while passing a number for how deep you are, base case being no more levels to go, or the object is found.
Remember to return false or undefined if you don't find it, and the right object if you do! Good luck!

Is there any way to retrieve the name for a gist that github displays

When I browse to a gist on gist.github.com it displays a friendly name. E.g. for
https://gist.github.com/stuartleeks/1f4e07546db69b15ade2 it shows stuartleeks/baz
This seems to be determined by the first file that it shows in the list of files for the gist, but I was wondering whether there is any way to retrieve this via the API?
Not directly, but you can get with the Gist API the JSON information associated to a gist, reusing the id of your url:
GET /gists/:id
In your case: https://api.github.com/gists/1f4e07546db69b15ade2
It includes:
"files": {
"baz": {
"filename": "baz",
and:
"owner": {
"login": "stuartleeks",
That should be enough to infer the name stuartleeks/baz.

Resources