Flutter how to add doc id with data - flutter

I ma just entering my data in Firestore. I need to know how can I put my doc id in data?
My simple code
_firestore.collection('Users').add({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': 'here i need doc id '
});
More explanation
From image you can see I need this document id in my data.

Do it like this:
String id = FirebaseFirestore.instance.collection('Users').doc().id;
FirebaseFirestore.instance.collection('Users').doc(id).set({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': id,
});

You can get the ID before you create the new document with add and use set instead of add:
final document = _firestore.collection('Users').doc();
_firestore.collection('Users').doc(document.id).set({
'shopname': 'Aam Dukaan',
'number': '9232313131',
'lastupdate': '',
'sendQty': '',
'id': 'here i need doc id '
});

You can add a document with desired id.
final usersRef = FirebaseFirestore.instance.collection("Users");
String id = "123";
usersRef.doc(id).set(
{
"name":"somename" ,
"id":"$id",
}

Related

Word addin inserting complex list structure with styling in a contentControl using office.js done or not?

I'm trying to insert a complex list structure into a contentControl in MS Word using the javascript API. The structure is build according to an object that contains nested arrays: Different items containing sub items that contain different properties. These items arrays can change in size so it needs to be generic. Maybe the Office.js API isn't really build for what I am trying to achieve and I should be using either insertHTML (with the structure build in HTML) or OOXML.
This is the structure I already build
The function that produced this:
import ContentControl = Word.ContentControl;
import {formatDate} from '../formatters';
let firstItem = true;
let listId;
export async function resolveItems(contentControl: ContentControl, data: Array<any>, t) {
Word.run( contentControl, async (context) => {
contentControl.load('paragraphs');
await context.sync();
for (const item of data) {
if (firstItem) {
const firstPara = contentControl.paragraphs.getFirst();
firstPara.insertText('ITEM (' + formatDate(item.date) + ')', 'Replace');
firstItem = false;
const contactList = firstPara.startNewList();
contactList.load('id');
await context.sync().catch((error) => {
console.log('Error: ' + error);
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
listId = contactList.id;
} else {
const otherItem = contentControl.insertParagraph('ITEM (' + formatDate(item.date) + ')', 'End');
otherItem.load(['isListItem']);
await context.sync();
otherItem.attachToList(listId, 0);
}
for (const subItem of item.subItems) {
let descriptionParaList = new Array();
let subItemPara = contentControl.insertParagraph(subItem.title + ' (' + formatDate(subItem.date) + ')', 'End');
subItemPara.load(['isListItem']);
await context.sync();
if (subItemPara.isListItem) {
subItemPara.listItem.level = 1;
} else {
subItemPara.attachToList(listId, 1);
}
let descriptions = subItem.descriptions;
for (const description of descriptions) {
let descriptionPara = contentControl.insertParagraph('', 'End');
descriptionPara.insertText(t(description.descriptionType) + ': ', 'Start').font.set({
italic: true
});
descriptionPara.insertText(description.description, 'End').font.set({
italic: false
});
descriptionPara.load(['isListItem', 'leftIndent']);
descriptionParaList.push(descriptionPara);
}
await context.sync();
for (const subItemPara of descriptionParaList) {
if (subItemPara.isListItem) {
subItemPara.detachFromList();
}
subItemPara.leftIndent = 72;
}
}
}
return context.sync().catch((error) => {
console.log('Error: ' + error);
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
});}
The data structure looks like this:
'LAST_5_Items': [
{
'date': '2019-03-14T14:51:29.506+01:00',
'type': 'ITEM',
'subItems': [
{
'date': '2019-03-14T14:51:29.506+01:00',
'title': 'SUBITEM 1',
'descriptions': [
{
'descriptionType': 'REASON',
'description': 'Reason 1',
'additionalInformation': ''
}
]
},
{
'date': '2019-03-14T14:51:29.506+01:00',
'title': 'SUBITEM 2',
'descriptions': [
{
'descriptionType': 'REASON',
'description': 'Reason 1',
'additionalInformation': ''
}
]
}
]
},
{
'date': '2019-03-14T14:16:26.220+01:00',
'type': 'ITEM',
'subItems': [
{
'date': '2019-03-14T14:16:26.220+01:00',
'title': 'SUBITEM 1',
'descriptions': [
{
'descriptionType': 'REASON',
'description': 'Reason 1',
'additionalInformation': ''
}
]
},
{
'date': '2019-03-14T14:16:26.220+01:00',
'title': 'SUBITEM 2',
'descriptions': [
{
'descriptionType': 'REASON',
'description': 'Reason 1',
'additionalInformation': ''
},
{
'descriptionType': 'SUBJECTIVE',
'description': 'Subjective 1',
'additionalInformation': ''
},
{
'descriptionType': 'SUBJECTIVE',
'description': 'Subjective 2',
'additionalInformation': ''
},
{
'descriptionType': 'OBJECTIVE',
'description': 'Objective 1',
'additionalInformation': ''
},
{
'descriptionType': 'OBJECTIVE',
'description': 'Objective 2',
'additionalInformation': ''
},
{
'descriptionType': 'EVALUATION',
'description': 'Evaluation',
'additionalInformation': ''
},
{
'descriptionType': 'REASON',
'description': 'Reason 1',
'additionalInformation': ''
}
]
}
]
}
]
What I am trying to achieve is a template resolver. The addin will allow the user to put placeholder (ContentControls), tags like First name, Last name,... and the 5 last contacts (the one I am now describing) in the document and when he resolves the file it will fetch all the data needed and start replacing the ContentControls with this structured layout.
Yes the code works, but I highly doubt that the code is well structured with so many context.sync() calls. It is too slow and it is not usable.
I need so many context.sync() because I need the properties of the List ID and if a Paragraph belongs to a list.
Is there a better way to achieve what I am trying to achieve using the office.js API?
Ideally the queue should be synced once so the user would not see the content being added and changed in a very strange way like it is now behaving.
Thanks
There is a technique for avoiding having context.sync inside a loop. The basic idea is that you have two loops, with a single context.sync in between them. In the first loop, you create an array of objects. Each object contains a reference to one of the Office objects that you want to process (e.g., change, delete, etc.) It looks like paragraphs in your case. But the object has other properties. Each of them holds some item of data that you need to process the object. These other items may be properties of other Office objects or they may be other data. Also, either in your loop or just after it, you load all the properties you're going to need of all the Office objects in the objects in your array. (This is usually easier to do inside the loop.)
Then you have context.sync.
After the sync, you loop through the array of objects that you created before the context.sync. The code inside this second loop processes the first item in each object (which is the Office object that you want to process) using the other properties of the object you created.
Here are a couple of examples of this technique:
My answer to this StackOverflow question: Document not in sync after replace text.
This code sample:
https://github.com/OfficeDev/Word-Add-in-Angular2-StyleChecker/blob/master/app/services/word-document/word.document.service.js.

how to create a CreativeAsset in dfp api

I'm trying to create an asset (CreativeAsset) to be used in a template Creative later. I cannot find in the documentation any way to create the asset itself, only to provide the base64 bytes, but I'd like to use this asset in multiple places, so I would prefer to load it once..Is there a way to create only a CreativeAsset?
https://developers.google.com/doubleclick-publishers/docs/reference/v201705/CreativeService.CreativeAsset
Here is the solution from the DFP API team:
A CreativeAsset must be created as a part of a creative. There is no dedicated service to create a CreativeAsset alone. But then, you can use the assetId to copy a CreativeAsset to a new creative. Basically, you can first create a creative, then get the creative asset's assetId and use it to create multiple creatives
This is a code example using python:
with open(f, "rb") as html_file:
html_file_data = base64.b64encode(html_file.read())
html_file_data = html_file_data.decode("utf-8")
# USING TEMPLATE
creative1 = {
'xsi_type': 'TemplateCreative',
'name': '',
'advertiserId': '',
'size': {'width': 1, 'height': 1},
'creativeTemplateId': '',
'creativeTemplateVariableValues': [
{
'xsi_type': 'AssetCreativeTemplateVariableValue',
'uniqueName': 'HTMLFile',
'asset': {
'assetByteArray': html_file_data,
'fileName': ''
}
}
# other variables
]
}
# USING CUSTOM
creative2 = {
'xsi_type': 'CustomCreative',
'name': '',
'advertiserId': '',
'size': {'width': 1, 'height': 1},
'destinationUrl': '',
'customCreativeAssets': []
}
creative2['customCreativeAssets'].append({
'xsi_type': 'CustomCreativeAsset',
'macroName': '',
'asset': {
'assetByteArray': html_file_data,
'fileName': ''
}
})
creative_service = dfp_client.GetService('CreativeService', version='v201702')
upload_creative1 = creative_service.createCreatives(creative1)
upload_creative2 = creative_service.createCreatives(creative2)
I hope this works.

TYPO3 - MySQL to mm Query Syntax

I have an working MySQL Query now i need it to convert to Typo3 Syntax
SELECT
tt_news_tx_extendnews_subscriber_mm.uid_local,
fe_users.*
FROM fe_users
JOIN tt_news_tx_extendnews_subscriber_mm
ON tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid
WHERE tt_news_tx_extendnews_subscriber_mm.uid_local = 101
TYPO3
$res0 = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
'fe_users',
'tt_news_tx_extendnews_subscriber_mm',
'tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid',
'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
'',
'',
''
);
the result is empty...anybody knows how this work with typo3?
Debug brings this: $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
SELECT tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*
FROM fe_users,tt_news_tx_extendnews_subscriber_mm,tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid
WHERE fe_users.uid=tt_news_tx_extendnews_subscriber_mm.uid_local
AND tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid.uid=tt_news_tx_extendnews_subscriber_mm.uid_foreign tt_news_tx_extendnews_subscriber_mm.uid_local = 101
By exec_SELECT_mm_query the 4th parameter is the foreign key table name, not the reference. You need instead of:
tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid
only:
fe_users
See more details in TYPO3 api : exec_SELECT_mm_query.
I think, you can try the following:
$res0 = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
'tt_news',
'tt_news_tx_extendnews_subscriber_mm',
'fe_users',
'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
'',
'',
''
);
Or you can use exactly the SQL what you have with the following little trick, because exe_SELECTquery only concats your string to SELECT..., FROM... (and so on...) parts. So because of this, you can use a JOIN in FROM part.
$res0 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
'fe_users
JOIN tt_news_tx_extendnews_subscriber_mm
ON tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid',
'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
'',
'',
'');

How to do a FQL query with JS SDK?

This is my code but doesn't work:
FB.api(
{
method: 'fql.query',
query: 'SELECT uid, first_name, last_name FROM user WHERE uid=100002306311953'
},
function(data) {
alert(data.uid);
}
);
});
I get "undefined" in the alert.
Why ?
Welcome to SO!
You can use the FB.api function by passing the fql.query method and the query,
A simple query that returns the current user, name:
FB.api({
method: 'fql.query',
query: 'SELECT uid, name FROM user WHERE uid = me()'
}, function(data) {
console.log(data);
var res = data[0].name;
alert(res);
}
);
FB Docs: https://developers.facebook.com/docs/reference/fql/

orientdb, how insert document field

I can try to insert into users class ( aka like a table) via shell a structure like this:
email: 'test#domain.com'
display_name: 'name surname test'
tags: {id: 1, name: 'first', type:'something'}
so some fields when one of them is a document.
I try this query:
insert into users (email, display_name, tags) values
('test#domain.com',
'name surname test',
{'id': 1, 'name': 'first', 'type' : 'something'}
)
but obtain this error:
Error: com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #52: Set of values is missed. Example: ('Bill', 'Stuart', 300)
Command: insert into users (email, display_name, tags) values
('test#domain.com',
'name surname test',
{'id': 1, 'name': 'first', 'type' : 'something'},
)
------------------------------------------------------------^
How can I insert this data into users class?
it's a problem of carriage return. This has been fixed works with 1.0-SNAPSHOT. To avoid to update your OrientDB distribution just remove \n.